how to bind ASP.Net DropDownList control in EditItemTemplate of GridView on edit(imagebutton)click

后端 未结 5 1963
悲哀的现实
悲哀的现实 2021-01-07 12:21

I have requirement to bind ASP.Net DropDownList control in EditItemTemplate of GridView. I have a edit imagebutton with commandname=\"Edit\"also dropdown needs to be binded

5条回答
  •  温柔的废话
    2021-01-07 12:53

    Code: Try this

    protected void gv_RowDataBound(object sender, GridViewEditEventArgs e)
        {
         if (e.Row.RowType == DataControlRowType.DataRow)
          {
                if ((e.Row.RowState & DataControlRowState.Edit) > 0)
                {
                  DropDownList ddList= (DropDownList)e.Row.FindControl("DStatusEdit");
                  //bind dropdownlist
                  DataTable dt = con.GetData("select distinct status from directory");
                  ddList.DataSource = dt;
                  ddList.DataTextField = "YourCOLName";
                  ddList.DataValueField = "YourCOLName";
                  ddList.DataBind();
    
                  DataRowView dr = e.Row.DataItem as DataRowView;
                  //ddList.SelectedItem.Text = dr["YourCOLName"].ToString();
                  ddList.SelectedValue = dr["YourCOLName"].ToString();
                }
           }
        }
    

    Have already answer similar question Binding dropdownlist inside gridview edititemtemplate

    View Blog Article : How to bind drop-down list inside gridview edit template

提交回复
热议问题