【问题标题】:How to get text of hyperlink which is in grid-view and send that text to another page如何获取网格视图中的超链接文本并将该文本发送到另一个页面
【发布时间】:2014-03-14 15:57:33
【问题描述】:

我的场景是从我的数据库中获取故事数据 n 标题并显示在 gridview 现在标题是当用户单击任何链接时的超链接,然后超链接的文本发送到阅读器页面,故事通过标题文本从数据库中获取。我该怎么做,请帮帮我..

【问题讨论】:

  • 当你点击任何链接时,请解释一下??
  • “不工作”是什么意思? DR1.GetValue(0).ToString();调试时有价值吗?编辑:还有 str = ?页面何时加载?
  • 你能粘贴你的gridveiw代码来回答吗?
  • 看看忘记我的代码它是一个实验我想要我描述的场景。当任何读者打开页面时,gridview 中的所有标题都会显示,现在用户点击标题链接。
  • 我是一个初学者,所以我不知道如何实现这个,你能把相关代码或链接发给我吗。

标签: c# asp.net


【解决方案1】:
<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>

【讨论】:

  • @WellCome 有帮助
猜你喜欢
  • 1970-01-01
  • 2021-12-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-12-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多