如何取得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![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
7
DataKey key=GridView1.DataKeys[index];
8![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
9
string customers = key.Value.ToString();
10![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
11
Session["customers"] = customers;
12
Server.Transfer("details.aspx");
13
}
14
}
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
2
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
3
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
4
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
5
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
6
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
7
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
8
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
9
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
10
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
11
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
12
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
13
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
14
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)