2012-04-23 54 views
0

嗨我使用DataGridView通過映射來自數據庫的URL,我已經在Hyperlinkfield中給出它(例如:將有10-20個鏈接將顯示在datagridview中)如果特定人員單擊特定鏈接,然後必須通過增加該特定URL的數據庫中的計數列來重定向到該特定URL。數據網格查看ASP.Net中的超鏈接C#

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

+0

什麼問題? – 2012-04-23 05:34:52

回答

0

你可以做到這一點在該行命令事件

創建一個動態點擊你想給

0

使用CommandArgument,做你的東西在GridView的onrowcommand事件的URL。

<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(""); 
    } 
    }