如何获得的GridView行值的文本框? [英] How to get text boxes for Gridview Row values?

查看:190
本文介绍了如何获得的GridView行值的文本框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用C#和放大器; Mysql的

Using C# & Mysql

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

In my webpage am using gridview, if i click the column in the girdview the value should display in the textbox.

例如

Griview

Column1 column2 Column3

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

如果我点击2行中的所有值应在文本框中显示

If i click the 2 rows all the values should display in the textbox

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

如何写一个code这个条件。

How to write a code for this condition.

需要C#code帮助

推荐答案

我假设,通过陈述的 [...]点击2行[...] 的你实际上意味着单击第二行的;至少,这是你最后片段暗示的东西,因为它显示了第二排的唯一值(一个小侧面说明:该ID的不对劲的地方,它应该是 7890 )。

I'm assuming that by stating "[...]click the 2 rows[...]" you actually mean "click the 2nd row"; 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).

以下code片段展示了一个 GridView控件,允许单个行的选择,并在$ C $使用一个事件处理程序的C-背后设置每个文本文本框来选择行中的值按:

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:

Page.aspx 的:

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

在$ C $事件处理C-隐藏文件中的 Page.aspx.cs 的:

Event handler in the code-behind file 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 */;
}

这篇关于如何获得的GridView行值的文本框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆