Binding dropdownlist inside gridview edititemtemplate

前端 未结 5 1161
终归单人心
终归单人心 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条回答
  •  甜味超标
    2020-12-14 12:29

    protected void gvProject_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            try
            {
                string Active = "";
                if (e.Row.DataItem != null)
                { 
                    if ((e.Row.RowState & DataControlRowState.Edit) > 0)
                    {
                        Label lblEditActive = (Label)e.Row.FindControl("lblUP_ET_ActiveStatus");
                        if (lblEditActive.Text != string.Empty)
                        {
                            Active = lblEditActive.Text.Trim();
                        }
    
                        DropDownList ddlActive = (DropDownList)e.Row.FindControl("ddlUP_ET_ActiveStatus");
                        ddlActive.Items.Clear();
                        ddlActive.Items.Add("True");
                        ddlActive.Items.Add("False"); 
                        ddlActive.DataBind(); 
                        ddlActive.Items.FindByText(Active).Selected = true;
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }       
    

提交回复
热议问题