vb.net 从网格视图中检索单元格数据以在文本框 VB ASP.NET 中输出

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14263219/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 11:51:31  来源:igfitidea点击:

Retrieve cell data from grid view to output in textbox VB ASP.NET

asp.netvb.netvisual-studio-2010

提问by Ibrahim

I am creating a website on Visual studio 2010. i am creating it on asp.net with Visual Basic coding. I am a university student and am a beginner with this.

我正在 Visual Studio 2010 上创建一个网站。我正在使用 Visual Basic 编码在 asp.net 上创建它。我是一名大学生,并且是这方面的初学者。

Basically i created a sqlDataSource and a Grid View and linked them together with drop down boxes so that the user can refine their table results. On the grid viewer i also turned on the 'select' feature so that the user can select a row.

基本上我创建了一个 sqlDataSource 和一个网格视图,并用下拉框将它们链接在一起,以便用户可以优化他们的表结果。在网格查看器上,我还打开了“选择”功能,以便用户可以选择一行。

What i am struggling to do is to retrieve at least one of the cells of the selected row in the grid view and put it into a textbox on the same page. The main cell i want to retrive is the ID so that i can use later.

我正在努力做的是检索网格视图中所选行的至少一个单元格,并将其放入同一页面上的文本框中。我要检索的主要单元格是 ID,以便我以后可以使用。

Please could you help me find a suitable solution for this.

请你帮我找到一个合适的解决方案。

Thank you

谢谢

回答by tam tam

This is in C# but the event is the same that you will target. When the user selects a row, this event will be fired and it will retrieve the selected row. Once you have the selected row you could get any column value of that row by using the index of the column.

这是在 C# 中,但事件与您将定位的事件相同。当用户选择一行时,将触发此事件并检索所选行。选定行后,您可以使用列的索引获取该行的任何列值。

void GridView1_SelectedIndexChanged(Object sender, EventArgs e)
{
    // Get the currently selected row using the SelectedRow property.
    GridView1 row = GridView1.SelectedRow;

    // You could access any cell in the row by doing row.cells(index)
    MessageLabel.Text = "You selected " + row.Cells[2].Text + ".";
}

Hope that helps!

希望有帮助!

EDIT

编辑

VB

VB

Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)

    ' Get the currently selected row using the SelectedRow property.
    Dim row As GridViewRow = GridView1.SelectedRow

    MessageLabel.Text = "You selected " & row.Cells(2).Text & "."

  End Sub