DropDownList绑定参考1
<EditItemTemplate>
<asp:DropDownList id="DropDownList1" runat="server" Width="100%" DataValueField="OID" DataTextField="cName" SelectedIndex='<%# GetDeptIndex(DataBinder.Eval(Container.DataItem,"ID").ToString()) %>' DataSource="<%# GetDeptInfo() %>">
</asp:DropDownList>
</EditItemTemplate>
//代码中
//数据源
public DataTable GetDeptInfo()
{
return table;
}
//默认绑定索引
public int GetDeptIndex(string oid)
{
......
return 0;
}
<asp:DropDownList id="DropDownList1" runat="server" Width="100%" DataValueField="OID" DataTextField="cName" SelectedIndex='<%# GetDeptIndex(DataBinder.Eval(Container.DataItem,"ID").ToString()) %>' DataSource="<%# GetDeptInfo() %>">
</asp:DropDownList>
</EditItemTemplate>
//代码中
//数据源
public DataTable GetDeptInfo()
{
return table;
}
//默认绑定索引
public int GetDeptIndex(string oid)
{
......
return 0;
}