简体   繁体   English

如何将GridView的值放入一个下拉列表

[英]how to get gridview value into a dropdownlist

I am working on a project in asp.net c#. 我正在asp.net c#中的一个项目上。 i want to retrieve the GridView value/data into TextBox and DropdownList and perform an update. 我想将GridView值/数据检索到TextBoxDropdownList并执行更新。 it seems to work for the TextBox but the DropdownList seems not to work. 它似乎适用于TextBoxDropdownList似乎不起作用。 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. 您可能需要将ListItem添加到DropDownList,而不是更改Text属性。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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