选择单个单元格asp.net时选择整行 [英] select an entire row when selecting a single cell asp.net
问题描述
您好b $ b
我希望能够从asp.net的网格视图中获取所选行。
基本上我的最后一列是一个链接列,每当点击链接我需要得到第一列的值(这也是一个隐藏的列)。
所以这里是一个例子:
ID(隐藏)|名称|姓氏|链接
----------------------------------------
0 |亚历克斯| Garrix |更改
所以当点击更改时,我需要在选择行中的值时找到[0]的隐藏列,但是asp.net没有selectedrow.column [0] .item.Value(应该是0)选项,那么如何在asp.net中实现呢?
亲切问候
Hi
I want to be able to get a selected row from a grid view in asp.net.
basically my last column is a link column and whenever clicking the link I need to get the value of the first column (which is also a hidden column).
So here is and example :
ID (hidden)| Name | surname | link
----------------------------------------
0 | Alex | Garrix | Change
so when clicking change, I need to find the hidden column of [0] when a value in the row is selected, but asp.net does not have the selectedrow.column[0].item.Value (which should then be 0) option, so how can I achieve this in asp.net?
Kind Regards
推荐答案
fisrt添加Gridview选择按钮
当你绑定gridview那个时候在viewState中存储你的数据表{data]
网格有行命令evevnt
protected void Grid1_RowCommand(object sender,GridViewCommandEventArgs e)
{
fisrt Add Gridview select button
when u r binding gridview that time store ur data table in viewState{"data"]
Grid Have row command evevnt
protected void Grid1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Select")
{
int num = Convert.ToInt32(e.CommandArgument);
//你将获得num
//假设数据表中存在ID列现在你可以使用以下方法轻松获取值
DataTable dt = ViewState [data] as DataTable;
string s = dt.Rows [num] [ID]。toString();
}
}
// u will get selected row number in num
//suppose ID column present in data table now u can easily fetch value using following
DataTable dt=ViewState["data"] as DataTable;
string s=dt.Rows[num]["ID"].toString();
}
}
这篇关于选择单个单元格asp.net时选择整行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!