获取数据表的选定行

获取数据表的选定行

本文介绍了获取数据表的选定行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个dataTable加载了数据,并设置为gridview控件的数据源.

当我单击该网格视图上的任何行时,我只需要获取该行.

I have a dataTable loaded with data, and set as a datasource for a gridview control.

When I click on any of the row on that gridview, I need to get that row only.

How is that possible?

推荐答案

Dim dataRows() As DataRow = dtChattable.Select(String.Format("Column1 LIKE '{0}%' AND Column3 = '{1}'", _
TextBox1.Text, TextBox2.Text))


<asp:CommandField HeaderText="Select" ShowSelectButton="True" />



现在,当用户选择特定的行时,将触发GridView的Row_Command事件.所以你要做这样的事情



Now when user selects a particular row, Row_Command event of the GridView is fired. So you do something like this

Protected Sub GridView1_RowCommand(sender As Object, e As GridViewCommandEventArgs)
    If e.CommandName = "Select" Then
        'get the row index

        Dim rowIndex As Integer = Convert.ToInt32(e.CommandArgument) - 1 'in case there is no paging.
        'Now get the value from GridView against this row.
        'perform required operation
    End If
End Sub




顺便说一句,您也可以尝试使用Google搜索解决方案: [ ^ ]

希望这可以帮助! :thumbsup:




By the way, you could have also tried Googling for a solution: select a row in gridview[^]

Hope this helps! :thumbsup:


CStr(datagridview1.Item(0, datagridview1.CurrentCell.RowIndex).Value())



这将获得选择行第一列的值

希望您使用vb.net



this will get the value of the first column of the select row

am hoping ur using vb.net


这篇关于获取数据表的选定行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 00:15