我正在尝试在新闻brief
描述的末尾向我的新闻门户添加阅读更多选项。到目前为止,一切似乎都运行良好,显示了 20 条最新记录。但是只要我在 gridview 中添加这段代码。只显示第一条记录,阅读更多链接似乎不起作用。
<asp:HyperLink ID="hlRead" runat="server" Font-Bold="True" Font-Size="Small"
Font-Underline="True" ForeColor="#0099FF"
NavigateUrl='<%# "news_details.aspx?id=" + Session["id"].ToString() %>'>Read More</asp:HyperLink>
这就是 ItemTemplate 的样子
<ItemTemplate>
<asp:LinkButton ID="name3" runat="server"
CommandArgument="<%# Container.DataItemIndex %>" CommandName="news"
Font-Underline="False" Text='<%# Eval("headlines_n") %>' Font-Bold="True"
Font-Size="Large" ForeColor="#0D8CCF" />
<asp:Label ID="Label21" Visible="false" runat="server" Text='<%# Eval("nid") %>'></asp:Label>
<br />
<asp:LinkButton ID="LinkButton1" runat="server"
CommandArgument="<%# Container.DataItemIndex %>" CommandName="news"
Font-Underline="False" Text='<%# Eval("brief") %>' />
<asp:HyperLink runat="server" Font-Bold="True" Font-Size="Small"
Font-Underline="True" ForeColor="#0099FF"
NavigateUrl='<%# "news_details.aspx?id=" + Session["id"].ToString() %>'> read more</asp:HyperLink>
<br />
<br />
</ItemTemplate>
这是服务器端代码:
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
switch (e.CommandName.Trim())
{
case "news":
try
{
int r1 = Int32.Parse((e.CommandArgument).ToString());
r1 = r1 % 9;
Label lbid1 = (Label)GridView1.Rows[r1].FindControl("Label21"); //Label 21 fetches the newsid from the database.
Session["id"] = lbid1.Text;
Response.Redirect("news_details.aspx?id=" + Session["id"]);
}
catch (Exception ex)
{
Response.Write(ex.ToString());
}
break;
}
}