簡體   English   中英

如何獲取網格視圖中的超鏈接文本並將其發送到另一頁

[英]How to get text of hyperlink which is in grid-view and send that text to another page

我的場景是從數據庫中獲取故事數據n標題,並顯示在gridview中,現在,當用戶單擊任何鏈接時,標題為超鏈接,然后將超鏈接的文本發送到閱讀器頁面,並通過標題文本從數據庫中獲取故事。 我該怎么辦,請幫幫我。

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" OnRowDataBound="CustomersGridView_RowDataBound" DataKeyNames="storyid" DataSourceID="yourdatasource">
<Columns>
<asp:BoundField DataField="StoryData" HeaderText="StoryData" InsertVisible="False" ReadOnly="True" SortExpression="StoryData" />
<asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" />
</Columns>
</asp:GridView>




<script runat="server">
    void CustomersGridView_RowDataBound(Object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowIndex >= 0)
        {
            HyperLink link = new HyperLink();
            link.Text = e.Row.Cells[1].Text.ToString();
            link.NavigateUrl = @"ReaderPage.aspx?StoryTitle=" + e.Row.Cells[1].Text.ToString();
            link.Attributes.Add("onmouseover", "this.style.backgroundColor='red'");
            link.Attributes.Add("onmouseout", "this.style.backgroundColor='#E9EDF1'");
            link.Target = "_blank";
            e.Row.Cells[1].Controls.Add(link);
        }

    }
</script>

暫無
暫無

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

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