我在这个页面中创建了一个DataGrid,并在模板列中绑定了一个DropDownList.由于要设置DropDownList的一些属性,我必须先取得它的一个句柄.可是我用下面的方法返回的却是空.我刚接触DataGrid,请各位指教!
private void Page_Load(object sender, System.EventArgs e)
{
if(!Page.IsPostBack)
{
........................
//drpLstStates is the ID
Control myControl = dtGrdCntcts.FindControl("drpLstStates");
........................
}
}
private void Page_Load(object sender, System.EventArgs e)
{
if(!Page.IsPostBack)
{
........................
//drpLstStates is the ID
Control myControl = dtGrdCntcts.FindControl("drpLstStates");
........................
}
}
<ItemTemplate>
<asp:Label id=Label2 runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.状态") %>'>
</asp:Label>
</ItemTemplate>
<EditItemTemplate> <asp:DropDownList id="DropDownList1" runat="server" Width="78px" SelectedIndex='<%# GetStatusIndex(DataBinder.Eval(Container,"DataItem.状态").ToString())%>'>
<asp:ListItem Value="未完成">未完成</asp:ListItem>
<asp:ListItem Value="完成">完成</asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>
2. *.cs文件代码(一般只有这个事件中用到取值)
private void DataGrid1_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
DropDownList status=(DropDownList)e.Item.FindControl("DropDownList1");
....; //这里进行绑定
}