把LinkButton 的CommandArgument邦定ID编号
<asp:LinkButton ID="LinkButton1" runat="server" CommandArgument='<%# Eval("id") %>'><%# Eval("xinghao") %></asp:LinkButton>
然后分别在三个数据显示控件的用法如下
***GridView的LinkButton 获得值的用法只需要执行GridView的RowCommand事件****
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
int id = Convert.ToInt32(e.CommandArgument.ToString());//第一种
int id= Convert.toint32(((LinkButton)sender).CommandArgument.ToString());//第二种
}
*****DataList和Repater的用法一样,不过不是RowCommand事件了,而是ItemCommand事件****
protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
{
int id = Convert.ToInt32(e.CommandArgument.ToString());
}
protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
{
int id = Convert.ToInt32(e.CommandArgument.ToString());
}
- 本文标题: 获取GridView中索引行 ASP.NET
- 文章分类:【.NET/Web】
- 非特殊说明,本文版权归【胡同里的砖头】个人博客 所有,转载请注明出处.