一个星级用户的简单问题,大家来看看吧,关于DataGrid的。
DataGrid里有一模版列,里面有一DropDownList,如下:
<asp:datagrid id="DataGrid1" 。。。。>
<Columns>
......
<asp:TemplateColumn>
<ItemTemplate>
<asp:DropDownList id="DropDownList1" runat="server" DataSource="<%# getchild((DataRowView)Container.DataItem) %>">
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateColumn>
..................
然后在DataGrid1_ItemDataBound事件中:
private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
DropDownList dd=(DropDownList)e.Item.FindControl("DropDownList1"); //a行
dd.SelectedIndex=1; //这行报错,“未将对象引用到实例”
}
错误说明DropDownList没有定位到,也就是a行有问题,这种用法我多次使用过,从没有问题,今天很奇怪了,谁能看出是怎么回事??