如何取得GridView被隐藏列的值
ASP.NET2.0中的GRIDVIEW控件真是非常奇怪,不知道MS是怎么考虑的,在GRIDVIEW里,行索引被放在了CommandArgument里面,而不是像DataGrid那样可以利用this.MyDataGrid.DataKeys[e.Item.ItemIndex].ToString()方便的取出主键值.
在GridView中将主键CustomerID这一列设为隐藏Visible ="false" , 增加一个button列。同时要注意,将GridView的DataKeyNames设置为"CustomerID" .
在GridView1_RowCommand事件中取得EmployeeID列的值。
在GridView中将主键CustomerID这一列设为隐藏Visible ="false" , 增加一个button列。同时要注意,将GridView的DataKeyNames设置为"CustomerID" .
在GridView1_RowCommand事件中取得EmployeeID列的值。
1
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
2
{
3
if (e.CommandName == "Detail")
4
{
5
int index = Convert.ToInt32(e.CommandArgument);
6![]()
7
DataKey key=GridView1.DataKeys[index];
8![]()
9
string customers = key.Value.ToString();
10![]()
11
Session["customers"] = customers;
12
Server.Transfer("details.aspx");
13
}
14
}
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)2
{3
if (e.CommandName == "Detail")4
{5
int index = Convert.ToInt32(e.CommandArgument);6

7
DataKey key=GridView1.DataKeys[index];8

9
string customers = key.Value.ToString();10

11
Session["customers"] = customers;12
Server.Transfer("details.aspx");13
}14
}

浙公网安备 33010602011771号