日期:2014-05-18  浏览次数:20598 次

我在GRIDVIEW的FOOTERROW添加了一个DropDownList,请问我如何在后台获取这个DropDownList并给它赋初值?(从数据库取值)--在线等
我在GRIDVIEW的FOOTERROW添加了一个DropDownList(ID   DropDownList1),请问我如何在后台获取这个DropDownList并给它赋初值?从数据库表中查询值添入DropDownList的ITEMS中
我试过DropDownList   ddl=(DropDownList)GridView1.FooterRow.FindControl( "DropDownList1 ");
ddl.Items.Add( "dsdf ");
但是添加不进去,

------解决方案--------------------
if (e.Item.ItemType == ListItemType.Footer)
{
DropDownList ddl=(DropDownList)GridView1.FooterRow.FindControl( "DropDownList1 ");
ddl.Items.Add( "dsdf ");

}
要在ItemDataBound绑定列事件里写
------解决方案--------------------
//是Row 不是Item
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{

if (e.Row.RowType == DataControlRowType.Footer)
{
DropDownList dropTemp = (DropDownList)e.Row.FindControl( "DropDownList1 ");
if (dropTemp != null)
{
dropTemp.DataSource = BindDropDownList();//绑定的方法
dropTemp.DataTextField = "XXXX ";
dropTemp.DataTextField = "XXXX ";
dropTemp.DataBind();

dropTemp.SelectedIndex = dropTemp.Items.IndexOf(dropTemp.Items.FindByText(yourString));
}

}
}