日期:2014-05-20  浏览次数:20476 次

DataGrid中DropDownList绑定数据的问题,急啊!
前台:
<asp:datagrid   id= "dgFeeList "   runat= "server "   Width= "100% "   AutoGenerateColumns= "False "   OnLoad= "dgLoad ">
<Columns>
<asp:BoundColumn   DataField= "FeeName "   HeaderText= "费用名称 ">
<HeaderStyle   HorizontalAlign= "Center "   Width= "20% "> </HeaderStyle>
<ItemStyle   HorizontalAlign= "Center "> </ItemStyle>
</asp:BoundColumn>
<asp:BoundColumn   DataField= "FeeValue "   HeaderText= "费用金额 ">
<HeaderStyle   HorizontalAlign= "Center "   Width= "20% "> </HeaderStyle>
<ItemStyle   HorizontalAlign= "Center "> </ItemStyle>
</asp:BoundColumn>
<asp:BoundColumn   DataField= "RealYM "   HeaderText= "产生年月 ">
<HeaderStyle   HorizontalAlign= "Center "> </HeaderStyle>
<ItemStyle   HorizontalAlign= "Center "> </ItemStyle>
</asp:BoundColumn>
<asp:TemplateColumn   HeaderText= "选择发票 ">
<HeaderStyle   HorizontalAlign= "Center "   Width= "20% "> </HeaderStyle>
<ItemStyle   HorizontalAlign= "Center "> </ItemStyle>
<ItemTemplate>
<asp:DropDownList   id= "ddlInvoiceNo "   runat= "server "> </asp:DropDownList>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid>

后台:

if(dtInvoiceList.Rows.Count> 0)
{
DropDownList   ddlInvoiceNo   =   (DropDownList)   e.Item.Cells[3].FindControl( "ddlInvoiceNo ");  

ddlInvoiceNo.DataSource   =   dtInvoiceList;
ddlInvoiceNo.DataTextField   =   "InvoiceNO ";
ddlInvoiceNo.DataValueField   =   "InvoiceID ";
ddlInvoiceNo.DataBind();
}

现在的问题是,我写在ItemDataBound事件里,我想让DataGrid加载的时候就绑定下拉列表的数据,但是现在结果却是下拉列表是空的,什么都没有显示出来,请各位帮忙啊!

------解决方案--------------------
在DataGrid的ItemDataBound事件中
private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if ((e.Item.ItemType == ListItemType.Item)||(e.Item.ItemType == ListItemType.AlternatingItem))
{
DropDownList ddl = (DropDownList)e.Item.Cells[0].FindControl( "ddl1 ");
//你的绑定代码
}
}


------解决方案--------------------
代码ms没有问题,看看dtInvoiceList有没有数据?