Reputation: 9
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
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
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