ItemDataBound事件:
if (e.Item.ItemType==ListItemType.EditItem)
{
DropDownList ddl=(DropDownList)e.Item.Cells[0].FindControl("DropDownList1");
//绑定数据源
}
if (e.Item.ItemType==ListItemType.EditItem)
{
DropDownList ddl=(DropDownList)e.Item.Cells[0].FindControl("DropDownList1");
//绑定数据源
}
<asp:DropDownList id=DropDownList1 runat="server" Width="104px" DataValueField="templateid" DataTextField="name" DataSource="<%# TempDv() %>" SelectedIndex='<%# TempIndex(DataBinder.Eval(Container,"DataItem.templateid")) %>'>
</asp:DropDownList>
</EditItemTemplate>
public DataView TempDv()
{
return new DTemplate().GetTemplateDv();
} public int TempIndex(object templateid)
{
if (templateid==DBNull.Value)
//templateid=0;
return -1;
return new DTemplate().GetTemplateIndex((int) templateid);
}
DataGrid1.EditItemIndex = e.Item.ItemIndex;
//绑定DataGrid
//在这也可以绑定DropDownList
string[] BookStyle=new string[5]{"a","b","c","d","e"}; DropDownList1.Items.Clear();
for(int i=0;i<BookStyle.Length;i++)
DropDomnList1.Items.Add(BookStyle[i])
//