简体   繁体   English

如何在自动生成的Gridview中动态添加链接按钮

[英]How to add Link Button In dynamically in Autogenerated Gridview

How to add Link Button In dynamically in Autogenerated Gridview and How write onclick event for that link button. 如何在自动生成的Gridview中动态添加链接按钮,以及如何为该链接按钮编写onclick事件。

<asp:GridView ID="GridView4" runat="server" BorderColor="#3366CC" BorderStyle="None"
                            BorderWidth="1px" CellPadding="4" ShowHeaderWhenEmpty="True" Width="996px" HeaderStyle-Wrap="false"
                            ItemStyle-Wrap="false" OnRowDataBound="GridView4_RowDataBound">

                            <PagerSettings Mode="NextPreviousFirstLast" FirstPageText="First" LastPageText="Last"
                                NextPageText="Next" PreviousPageText="Previous" />
                            <FooterStyle BackColor="#99CCCC" ForeColor="#003399" />
                            <HeaderStyle BackColor="#003399" Font-Bold="True" ForeColor="#CCCCFF" Height="10px" />
                            <RowStyle ForeColor="white" HorizontalAlign="Center" Font-Names="Microsoft Sans Serif" />
                            <SelectedRowStyle BackColor="#009999" Font-Bold="True" ForeColor="#CCFF99" />
                            <SortedAscendingCellStyle BackColor="#EDF6F6" />
                            <SortedAscendingHeaderStyle BackColor="#0D4AC4" />
                            <SortedDescendingCellStyle BackColor="#D6DFDF" />
                            <SortedDescendingHeaderStyle BackColor="#002876" />
</asp:GridView>

Binded Datas to this gridview dynamically..the Header and data's changes everytime. 动态将数据绑定到此gridview。标题和数据的每次更改。

Need to bind all the datas in link button and to write code for that button click. 需要绑定链接按钮中的所有数据,并为该按钮单击编写代码。

Please help......................... 请帮忙.........................

You don't need to add a link button. 您无需添加链接按钮。
You need to add 您需要添加

  1. DataKeys, a comma separated list of fields from GridView4 Dataset DataKeys,以逗号分隔的GridView4数据集的字段列表
  2. Enable row selection 启用行选择
  3. Add a row selection handler 添加行选择处理程序

     <asp:GridView ID="GridView4" runat="server" AutoGenerateSelectButton="True" OnSelectedIndexChanged="GridView4_SelectedIndexChanged" DataKeyNames="XXX,YYY,ZZZ"> ... </asp:GridView 

Alternatively, the above can all be done in the code behind. 或者,以上所有操作都可以在后面的代码中完成。

Selecting a row will fire the event handler where you retrieve the data Keys 选择一行将触发事件处理程序,您可以在其中检索数据

    protected void GridView4_SelectedIndexChanged( object sender, EventArgs e )
    {
        // Retrieve data from selected row
        String field1 = (String) GridView1.SelectedDataKey.Values[ "XXX" ];
        int field2 = (int) GridView1.SelectedDataKey.Values[ "YYY" ];
        double field3 = (double) GridView1.SelectedDataKey.Values[ "ZZZ" ];

        PopulateYourOtherGridviewDataSource(field1, field2, field3);
        GridViewOther.DataBind();
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM