关于在DataGrid中动态绑定DropDownList的问题!
leang 2005-10-17 11:33:18 各位:
关于在DataGrid中动态绑定DropDownList,我看了论坛大部分都是将ItemTemplate用一个Label代替,在EditItemTemplate中用DropDownList。但是,假如我要在编辑时使得DropDownList显示的值与实际值匹配,而不总是显示第一行!我用如下代码:
<EditItemTemplate>
<asp:DropDownList id=ddlTitle runat="server" DataMember="Titles" DataSource="<%# dsTitles %>" SelectedValue='<%# DataBinder.Eval(Container, "DataItem.Title") %>' DataTextField="Title_Desc" DataValueField="Title" AutoPostBack="True">
</asp:DropDownList>
</EditItemTemplate>
出错!!!我在ItemDataBound事件中代码:
if (e.Item.ItemType == ListItemType.EditItem)
{
dsTitles.Clear();
sqlDATitles.Fill(dsTitles);
DropDownList ddl = (DropDownList)(e.Item.FindControl("ddlTitle"));
ddl.DataBind();
}