Binding dropdownlist inside gridview edititemtemplate

前端 未结 5 1153
终归单人心
终归单人心 2020-12-14 11:53

I\'m not able to bind my dropdownlist present in edititem template . I am getting null reference when i try to access it.

My design:



        
5条回答
  •  萌比男神i
    2020-12-14 12:49

    The event RowEditing occurs just before a row is edited.

    You should use the RowDataBound event instead.

    protected void gv_RowDataBound(object sender, GridViewRowEventArgs e)
    {
       if (gv.EditIndex == e.Row.RowIndex && 
           e.Row.RowType==DataControlRowType.DataRow) 
       {       
           DropDownList drpcategory1 = (DropDownList)e.Row.FindControl("drpcategory1"); 
           //bind the control
       }
    }
    

提交回复
热议问题