ASP.net C#:
gridview中
如何给FooterTemplate中的DropDownList控件赋值?
写在哪个事件里?请高手指教。谢谢!

解决方案 »

  1.   

    你想怎样赋值?可以在编辑模板的时候用Bind来绑定字段,也可以用gridview.findcontrol(id)方法来操作
      

  2.   

    我在Page_Load中用以下代码,老是报错,是怎么回事? GridViewRow footrow = GridView1.FooterRow;
     DropDownList ddl = (DropDownList)footrow.FindControl("DropDownList1");
     ddl.Items.Add("aaaaaa");(我用的是asp.net 2.0 )
      

  3.   


        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType = DataControlRowType.Footer)
            {
                DropDownList ddl = (DropDownList)e.Row.FindControl("DropDownList1"); 
            }
        }
      

  4.   

    谢谢楼上的,这样是可以,不过呢,我这个DropDownList 是设置成了AUTOPOSTBACK的,后面有个DropDownList 要根据前面的DropDownList 动态选值的,所以需求比较麻烦。不过,还是谢谢你。MS的这些控件真他的难用还是以前ASP年代用纯粹的手写方便点。
      

  5.   

    没什么麻烦的。给你DropDownList1 加上selectedindexchange事件然后在事件里边找到DropDownList2............
      

  6.   


        protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
        {
            //int index=((GridViewRow)(((DropDownList)sender).Parent.Parent)).RowIndex;
            ((DropDownList)GridView2.FooterRow.FindControl("DropDownList2")).SelectedValue = ((DropDownList)sender).SelectedValue;
        }