简体   繁体   English

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

[英]How to get text boxes for Gridview Row values?

Using C# & Mysql 使用C#和Mysql

In my webpage am using gridview, if i click the column in the girdview the value should display in the textbox. 在我的网页上使用gridview,如果我点击girdview中的列,该值应显示在文本框中。

For Example 例如

Griview Griview

Column1 column2 Column3

    1 Raja 9876
    2 Ravi 7890
    3 Ramu 9879
    ...

If i click the 2 rows all the values should display in the textbox 如果我单击2行,则所有值都应显示在文本框中

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

How to write a code for this condition. 如何为这种情况编写代码。

Need C# code Help 需要C#代码帮助

I'm assuming that by stating " [...]click the 2 rows[...] " you actually mean " click the 2nd row "; 我假设通过声明“ [...]点击2行[...] ”,你的意思是“ 点击第2行 ”; at least, this is what your last snippet suggests, since it shows only the values of the 2nd row (on a little side note: the ID's wrong there; it should be 7890 ). 至少,这是你的最后一个片段所暗示的,因为它只显示第二行的值(在一个小方面注释:ID错误;它应该是7890 )。

The following code snippet shows a GridView which allows the selection of a single row, and uses an event handler in the code-behind to set the text of each TextBox to the according value in the selected row: 以下代码片段显示了一个允许选择单行的GridView ,并在代码隐藏中使用事件处理程序将每个TextBox的文本设置为所选行中的相应值:

Page.aspx : Page.aspx

<asp:GridView runat="server" ID="gridView" OnSelectedIndexChanged="gridview_SelectedIndexChanged" AutoGenerateSelectButton="true"></asp:GridView>

Event handler in the code-behind file Page.aspx.cs : 代码隐藏文件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 */;
}

You can use an EditItemTemplate for this. 您可以使用EditItemTemplate

See the CodeProject article, Editable Gridview with Textbox, CheckBox, Radio Button and DropDown List . 请参阅CodeProject文章, 带文本框的可编辑网格视图,CheckBox,单选按钮和DropDown列表

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

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