簡體   English   中英

ASP.Net C#中的數據網格視圖超鏈接

[英]Data Grid View Hyper Link in ASP.Net C#

嗨,我正在使用DataGridView,它是通過映射數據庫的URL來實現的,例如我在Hyperlinkfield中為其指定的URL(例如:datagridview中將顯示10-20個鏈接),如果特定的人單擊特定的鏈接,則它必須重定向到該鏈接通過增加數據庫中該特定URL的“計數”列來增加該特定URL。

注意:iam在模板設計模式下使用datagridview。

您可以在row命令事件中執行此操作

使用您要提供的網址創建動態點擊

使用CommandArgument並在Gridview onrowcommand事件中進行操作。

<asp:GridView ID="GridView1" OnRowCommand="GridView1_RowCommand" runat="server">
        <Columns>
            <asp:TemplateField>
                <ItemTemplate>
                    <asp:LinkButton ID="btnUpdate" runat="server" CommandArgument='<%#Eval("LinkID")%>' CommandName="btnUpdate" Text='<%#Eval("LinkDisplayText")%>'>
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
    </asp:GridView>

protected void GridView1_RowCommand(Object sender, GridViewCommandEventArgs e)
  {
    if(e.CommandName=="btnUpdate")
    {
      int index = Convert.ToInt32(e.CommandArgument);
      //based on LinkID get the current click count from database.
      int icount;
      //increment the count
      //update the database once again and get the link as well.
      //redirect to the link
      Response.Redirect("");
    }
  }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM