简体   繁体   中英

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();

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));

尝试这可能对您有所帮助。

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM