asp.net gridview ItemTemplate 获得 一行 数据

来源:互联网 发布:淘宝摄影产品拍照商家 编辑:程序博客网 时间:2024/05/22 16:52

大多数情况是给按钮CommandName,然后在RowCommand事件中处理


<asp:TemplateField>    <ItemTemplate>        <asp:LinkButton ID="lnkbtnUp" runat="server" CommandName="up">Up</asp:LinkButton>      </ItemTemplate></asp:TemplateField>


protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e){    if (e.CommandName == "up")    {        int index = ((GridViewRow)((Button)e.CommandSource).NamingContainer).RowIndex;        //如果是TemplateField        string str = ((Label)(GridView1.Rows[index].FindControl("控件名"))).Text;        //如果是BoundField        string str = (GridView1.Rows[index].Cells[单元格索引].Text;    }}



http://bbs.csdn.net/topics/230014259

原创粉丝点击