Skip to content
Advertisement

how to bind dropdown list in a gridview from database and also edit and update it

I want to bind dropdown list in a gridview with datasiursce coming from data base, and i also want to edit and update it if required.

The datasource contains the data i want to fetch,its doesnt bind

            if (gvItem.Rows.Count > 0)
            {
                for (int i = 0; i < gvItem.Rows.Count; i++)
                {

                    DropDownList sup = (DropDownList)gvItem.Rows[i].FindControl("ddlsup");

                    baplan.Condition = "sup";
                    DataSet dss = new DataSet();
                    dss = baplan.getpro();

                    sup.DataSource = dss;
                    sup.DataBind();
                    sup.DataTextField = "Name";
                    sup.DataValueField = "Id";
                }
            }

Advertisement

Answer

if (gvItem.Rows.Count > 0)
    {
        for (int i = 0; i < gvItem.Rows.Count; i++)
        {

            DropDownList sup = (DropDownList)gvItem.Rows[i].FindControl("ddlsup");

            baplan.Condition = "sup";
            DataSet dss = new DataSet();
            dss = baplan.getpro();

            sup.DataSource = dss;

            sup.DataTextField = "Name";
            sup.DataValueField = "Id";
            sup.DataBind();


            }
        }
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement