user3216802
user3216802

Reputation: 9

how to get gridview value into a dropdownlist

I am working on a project in asp.net c#. i want to retrieve the GridView value/data into TextBox and DropdownList and perform an update. it seems to work for the TextBox but the DropdownList seems not to work. please any help.

 txtempcode.Text = GridView1.SelectedRow.Cells[1].Text.Replace(" ", "");
 dropdownlistgend.Text = GridView1.SelectedRow.Cells[2].Text.ToString();

Upvotes: 1

Views: 438

Answers (2)

I A Khan
I A Khan

Reputation: 8869

Try This may be help full.

DropDownList1.Items.Insert(0, new ListItem(GridView1.SelectedRow.Cells[2].Text.ToString(), GridView1.SelectedRow.Cells[2].Text.ToString()));

Upvotes: 0

Adil
Adil

Reputation: 148180

You probably need to add ListItem to DropDownList instead of changing Text property.

string gridValue = GridView1.SelectedRow.Cells[2].Text.ToString();
DropDownList1.Items.Insert(0, new ListItem(gridValue, gridValue));

Upvotes: 2

Related Questions