首页 .NET/Web 获取GridView中索引行 ASP.NET

获取GridView中索引行 ASP.NET

作者:胡同里的砖头 围观群众:1580 更新于:2013-12-19

把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】
  • 非特殊说明,本文版权归【胡同里的砖头】个人博客 所有,转载请注明出处.
留言评论
站点声明:
1、本站【胡同里的砖头】个人博客,借鉴网上一些博客模板,取其各优点模块自行拼装开发,本博客开发纯属个人爱好。
2、所有笔记提供给广大用户交流使用,可转载,可复制,纯个人开发所遇问题锦集记录使用
Copyright © huzlblog.com All Rights Reserved. 备案号:苏ICP备2021056683号-8