Set DropDownList Selected Value on GridView Edit Button Click using C# and VB.Net in ASP.Net

Last Reply 11 months ago By dharmendr

Posted 11 months ago

When i select row from gridview for editing, then in dropdownlist value(Sections) get change in popup window,

here is screen link , so i want that value which exit in row must display same in popup window dropdownlist.

here is c# code.

        protected void Edit(object sender, EventArgs e)
            using (GridViewRow row = (GridViewRow)((LinkButton)sender).Parent.Parent)
                txtEmpID.ReadOnly = true;
                txtEmpID.Text = row.Cells[0].Text;
                txtEmpName.Text = row.Cells[1].Text;
                txtFahterName.Text = row.Cells[2].Text;
               ddlSecID.SelectedItem.Value = row.Cells[3].Text;



Posted 11 months ago

Hi akhter,

For selecting the dropdownlist value you need to use FindByValue and set the selected value true.

For more details refer below article.

Populate DropDownList with Selected Value in EditItemTemplate of GridView in ASP.Net


akhter says:
ddlSecID.SelectedItem.Value = row.Cells[3].Text;

 Change with below code.

ddlSecID.Items.FindByValue(row.Cells[3].Text).Selected = true;