在单击按钮时从datagridview获取特定单元格的值 [英] Getting value of a particular cell from datagridview on button click

查看:194
本文介绍了在单击按钮时从datagridview获取特定单元格的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在datagridview中有一个按钮.单击此按钮后,我需要一列(数字-列名)的值,因为我需要显示该特定数字的详细信息.
任何人都可以帮我吗?

预先谢谢您.

I have a button in datagridview. After I click this button I need value of a column(number-column name) as I need to display details of that particular number.
Can any1 please help me out?

Thanking you in advance.

推荐答案

在网格视图的行命令事件处理程序中,编写类似这样的代码

in your row command event handler of the grid view, code something like this

Private Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles GridView1.RowCommand
 'create a variable to read the content of cell, the primary key of the record
       Dim myprimarykey As Integer
'read the value from the row(which is clicked) and cell (no) 
       myprimarykey=gridView1.Rows(e.CommandArgument).Cells.Item(0).Text
' write the code you want to be performed on it. e.g.
       MessageBox.Show("You pressed the button for the record" & myprimarykey)
end sub



您还可以利用e.CommandName(在设计gridview并添加按钮列时在按钮说明中输入命令名称)执行if-else,以检查按下了哪个按钮(如果网格提供了多种类型的按钮)

如需更多帮助,请参考
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridviewcommandeventargs.aspx [ ^ ]



you can also utilize e.CommandName (put the commandname in button description when designing gridview and adding a button column,) perform if-else to check which button was pressed (if the grid offers more than one type of button)

for more help, refer
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridviewcommandeventargs.aspx[^]


这篇关于在单击按钮时从datagridview获取特定单元格的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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