zoukankan      html  css  js  c++  java
  • GridVew linkbutton点击时获取点击行label的绑定值

    点击按钮事件

    protectedvoid LinkBtnUpdate_Click(object sender, EventArgs e)
    {

    LinkButton btn
    = (LinkButton)sender;
    //找到点击行
    GridViewRow irow = (GridViewRow)btn.NamingContainer;
    Label lbltag
    = (Label)irow.Cells[0].FindControl("Label1");
    string tbtag = lbltag.Text.Trim();
    Response.Write(tbtag);
    Response.Redirect(
    "Update.aspx?url=news1.aspx&NewsType=1&NewsId="+ tbtag +"");
    }

    前台绑定:

    <asp:GridView ID="GridTitle" runat="server" AutoGenerateColumns="False"
    CellPadding
    ="4" ForeColor="#333333" Width="100%"
    AllowPaging
    ="True" AllowSorting="True"
    onrowdatabound
    ="GridTitle_RowDataBound"
    onpageindexchanging
    ="GridTitle_PageIndexChanging" PageSize="10">
    <RowStyle BackColor="#EFF3FB"/>
    <Columns>
    <asp:TemplateField>
    <HeaderTemplate>
    序号
    </HeaderTemplate>
    <ItemTemplate>
    <%# Container.DataItemIndex +1%>
    </ItemTemplate>
    <ControlStyle Width="20px"/>
    <ItemStyle Width="70px"/>
    </asp:TemplateField>
    <asp:BoundField DataField="NewsTitle" HeaderText="标题">
    <ControlStyle Width="70%"/>
    </asp:BoundField>
    <asp:TemplateField>
    <HeaderTemplate>
    操作
    </HeaderTemplate>
    <ItemTemplate>
    <asp:LinkButton ID="LinkBtnUpdate" runat="server" onclick="LinkBtnUpdate_Click">编辑</asp:LinkButton>
    &nbsp;
    <asp:LinkButton ID="LinkBtnDelete" runat="server"
    onclick
    ="LinkBtnDelete_Click">删除</asp:LinkButton>
    </ItemTemplate>
    <ItemStyle Width="100px"/>
    </asp:TemplateField>
    <asp:TemplateField Visible="false">
    <ItemTemplate>
    <asp:Label ID="Label1" runat="server" Text='<%#Eval("NewsId") %>'>&apos;&gt;</asp:Label>
    </ItemTemplate>
    </asp:TemplateField>
    </Columns>
    <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White"/>
    <PagerTemplate>
    <table align="center" width="400px">
    <tr>
    <td width="50px">
    <asp:Label ID="Label1" runat="server"
    Text
    ="<%# ((GridView)Container.Parent.Parent).PageIndex + 1 %>"/>

    </td>
    <td width="50px">
    /<asp:Label ID="lblPageCount" runat="server"
    Text
    ="<%# ((GridView)Container.Parent.Parent).PageCount %>"/>

    </td>
    <td width="50px">
    <asp:LinkButton ID="btnFirst" runat="server" CausesValidation="False"
    CommandArgument
    ="First" CommandName="Page" Text="首页"/>
    </td>
    <td width="50px">
    <asp:LinkButton ID="btnPrev" runat="server" CausesValidation="False"
    CommandArgument
    ="Prev" CommandName="Page" Text="上一页"/>
    </td>
    <td>
    <asp:LinkButton ID="btnNext" runat="server" CausesValidation="False"
    CommandArgument
    ="Next" CommandName="Page" Text="下一页"/>
    </td>
    <td width="50px">
    <asp:LinkButton ID="btnLast" runat="server" CausesValidation="False"
    CommandArgument
    ="Last" CommandName="Page" Text="尾页"/>
    </td>
    </tr>
    </table>
    </PagerTemplate>
    <PagerStyle ForeColor="White" HorizontalAlign="Center"/>
    <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333"/>
    <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White"/>
    <EditRowStyle BackColor="#2461BF"/>
    <AlternatingRowStyle BackColor="White"/>
    </asp:GridView>
  • 相关阅读:
    ByteBuffer的mark、position、limit、flip、reset,get方法介绍ok
    java.nio.ByteBuffer的flip、rewind和compact几个方法的区分使用
    maven之一:maven安装和eclipse集成
    Java 8 函数式接口
    Lambda 表达式
    jdk8十大新的特性
    阿里巴巴73款开源产品列表,值得收藏
    【Java】java.util.Objects 工具类方法研究
    ARIMA 模型简单介绍
    python 二维数组取值
  • 原文地址:https://www.cnblogs.com/happygx/p/2044257.html
Copyright © 2011-2022 走看看