点击新闻标题跳转对应的页面如何设置
<A   href="./inews.aspx?news_id=<%#Eval("newsid") %>">

现在这里是设置成固定的页面,无论按哪个标题都是跳转同一个页面,应该如何设置成按不同标题跳转不同页面

Default2.aspx.cs代码

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.OleDb;
public partial class Default2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            bind();
        }
    }
    void bind()
    {
        string strconn = "Provider=Microsoft.ACE.OLEDB.12.0;" + @"data source = D:\ruanjian\office2010pjb_20398\ashujuku\stu.accdb";
        OleDbConnection conn = new OleDbConnection(strconn);
        string sql = "select top 9 * from news order by newstime DESC"; 
        conn.Open();
        OleDbDataAdapter da = new OleDbDataAdapter(sql, conn);
        DataTable dt1 = new DataTable();
        da.Fill(dt1);
        PagedDataSource pds = new PagedDataSource(); //创建分页的对象
        pds.DataSource = dt1.DefaultView;

        pds.AllowPaging = true;  //允许分页
        pds.PageSize = 4;        //分页数量
        pds.CurrentPageIndex = Convert.ToInt32(labPage.Text) - 1;  //当先页码
        Repeater1.DataSource = pds;  //指定数据来源

        LabCountPage.Text = pds.PageCount.ToString();  //共?页
        labPage.Text = (pds.CurrentPageIndex + 1).ToString(); //
        lbtnpritPage.Enabled = true;
        lbtnFirstPage.Enabled = true;
        lbtnNextPage.Enabled = true;
        lbtnDownPage.Enabled = true;
        if(pds.CurrentPageIndex < 1)
        {
            lbtnpritPage.Enabled = false;
            lbtnFirstPage.Enabled = false;
        }
        if(pds.CurrentPageIndex==pds.PageCount - 1)
        {
            lbtnNextPage.Enabled = false;
            lbtnDownPage.Enabled = false;
        }
        label1.Text = pds.DataSourceCount.ToString();//显示记录数
        Repeater1.DataBind();
        conn.Close();
    }


    protected void lbtnFirstPage_Click(object sender, EventArgs e)
    {
        labPage.Text = "1";
        bind();
    }

    protected void lbtnpritPage_Click(object sender, EventArgs e)
    {
        labPage.Text = Convert.ToString(Convert.ToInt32(labPage.Text) - 1);
        bind();
    }

    protected void lbtnNextPage_Click(object sender, EventArgs e)
    {
        labPage.Text = Convert.ToString(Convert.ToInt32(labPage.Text) + 1);
        bind();
    }

    protected void lbtnDownPage_Click(object sender, EventArgs e)
    {
        labPage.Text = LabCountPage.Text;
        bind();
    }

    protected void LinkButton1_Click(object sender, EventArgs e)
    {
        if(TextBox1.Text !="")
        {
            labPage.Text = TextBox1.Text;
            bind();
        }
    }
}

Default2.aspx代码

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
    <link href="css/ptu.css" rel="stylesheet" type="text/css" />
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <asp:Repeater ID="Repeater1" runat="server" > <ItemTemplate>  
               <div class="mmid_top_news">
                <div class="mmid_news_left"><img src="images/icon_arrow_blue.gif" width="4" height="7" /></div>
                <div class="mmid_news_mid"> <A   href="./inews.aspx?news_id=<%#Eval("newsid") %>">
                    <%# Eval("newstitle").ToString().Length > 20 ? Eval("newstitle").ToString().Substring(0, 20)+"..." : Eval("newstitle").ToString()%></div></A>
                <div class="mmid_news_right"><%#Convert.ToDateTime(Eval("newstime")).ToString("MM-dd")%></div> 
               </div>                
        </ItemTemplate></asp:Repeater>
        共<asp:Label runat="server" ID="label1"></asp:Label>条
        <asp:LinkButton ID="lbtnFirstPage" 
        runat="server"  BorderStyle="None" OnClick="lbtnFirstPage_Click">首页</asp:LinkButton>
                    <asp:LinkButton ID="lbtnpritPage" runat="server" 
        BorderStyle="None" OnClick="lbtnpritPage_Click" >上一页</asp:LinkButton>
                    <asp:LinkButton ID="lbtnNextPage" runat="server" 
        BorderStyle="None" OnClick="lbtnNextPage_Click" >下一页</asp:LinkButton>
                    <asp:LinkButton ID="lbtnDownPage" runat="server" 
        BorderStyle="None" OnClick="lbtnDownPage_Click" >尾页</asp:LinkButton>
        第<asp:Label ID="labPage" runat="server" Text="1"></asp:Label>页/共<asp:Label ID="LabCountPage" runat="server" Text="Label"></asp:Label>页
        <asp:LinkButton ID="LinkButton1" runat="server" 
            BorderStyle="None" OnClick="LinkButton1_Click">转到</asp:LinkButton><asp:TextBox ID="TextBox1" runat="server" Width="30px"></asp:TextBox>页

    </div>
    </form>
</body>
</html>

2个回答

href="./inews.aspx?news_id=<%#Eval("newsid") %>"

这里的 inews 这块区域设置成动态字段,并且你的分类对应页面的名称。不就好啦,不过这样也有局限性,
第二种办法 把href 中的连接地址直接存起来,作为一个字段绑定到页面。

一般情况下新闻详情页应该都是一样的吧,传不同的ID显示不同的内容。如果你想跳不同的页面也可以,你在数据中加个字段,就是跳转到的页面链接,然后同理
?news_id=<%#Eval("newsid") %>">,应该可以,具体的我没有试验,你可以试试

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐