如何获取Gridview Row值的文本框?

使用C#和Mysql

在我的网页上使用gridview,如果我点击girdview中的列,该值应显示在文本框中。

例如

Griview

Column1 column2 Column3 1 Raja 9876 2 Ravi 7890 3 Ramu 9879 ... 

如果我单击2行,则所有值都应显示在文本框中

 Textbox1.text = 2 textbox2.text = Ravi textbox3.text = 9879 ..., 

如何为这种情况编写代码。

需要C#代码帮助

我假设通过声明“ […]点击2行[…] ”,你的意思是“ 点击第2行 ”; 至少,这是你的最后一个片段所暗示的,因为它只显示第二行的值(在一个小方面注释:ID的错误;它应该是7890 )。

以下代码片段显示了一个允许选择单行的GridView ,并在代码隐藏中使用事件处理程序将每个TextBox的文本设置为所选行中的相应值:

Page.aspx

  

代码隐藏文件Page.aspx.cs中的事件处理程序:

 void gridview_SelectedIndexChanged(object sender, EventArgs e) { var grid = sender as GridView; if (grid == null) return; //Cell[0] will be the cell with the select button; we don't need that one Textbox1.Text = grid.SelectedRow.Cell[1].Text /* 2 */; Textbox2.Text = grid.SelectedRow.Cell[2].Text /* Ravi */; Textbox3.Text = grid.SelectedRow.Cell[3].Text /* 7890 */; } 

您可以使用EditItemTemplate

请参阅CodeProject文章, 带文本框的可编辑网格视图,CheckBox,单选按钮和DropDown列表