![](/img/trans.png)
[英]How to get the text of a hyperlink field inside a grid view in ASP .Net?
[英]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.