问题描述
为什么我获取不到下拉列表框里的银行信息,Text那里是null的<asp:TemplateFieldHeaderText="定金入账银行"ControlStyle-Width="70px"><EditItemTemplate><asp:DropDownListID="ddlBank"runat="server"Width="151px"></asp:DropDownList></EditItemTemplate><ItemTemplate><asp:LabelID="lblSex"runat="server"Text='<%#Eval("Bank")%>'></asp:Label></ItemTemplate></asp:TemplateField>protectedvoidGridView1_RowDataBound(objectsender,GridViewRowEventArgse){if(e.Row.RowType==DataControlRowType.DataRow){if(e.Row.RowState==DataControlRowState.Normal||e.Row.RowState==DataControlRowState.Alternate){LabellblSex=e.Row.FindControl("lblSex")asLabel;if(lblSex!=null){if(lblSex.Text=="0"){lblSex.Text="交通银行";}if(lblSex.Text=="1"){lblSex.Text="工商银行";}if(lblSex.Text=="2"){lblSex.Text="建设银行";}}//行的状态是:编辑状态或者(交替行且是编辑状态)if(e.Row.RowState==DataControlRowState.Edit||e.Row.RowState==(DataControlRowState.Alternate|DataControlRowState.Edit)){DropDownListddlBank=e.Row.FindControl("ddlBank")asDropDownList;if(ddlBank!=null){ListItemitem1=newListItem();item1.Value="0";item1.Text="交通银行";ddlBank.Items.Add(item1);ListItemitem2=newListItem();item2.Value="1";item2.Text="工商银行";ddlBank.Items.Add(item2);ListItemitem3=newListItem();item3.Value="2";item3.Text="建设银行";ddlBank.Items.Add(item3);}}
解决方案
解决方案二:
解决方案三:
http://www.cnblogs.com/jian1982/archive/2010/06/19/1760934.html参考需要在RowDataBound绑定数据并设置选中。