C# 使用超链接控件从数据库检索数据

C# 使用超链接控件从数据库检索数据,c#,asp.net,C#,Asp.net,大家好,因为我是asp.NETC的新手,我需要长者的帮助 有一个包含以下列的表: ID int unique not null Title varchar(250) not null Username varchar(100) not null Datetime datetime not null Shortviews varchar(500) not null Fullviews varchar(1000) not null Photo image not null 我已经成功地将页面编码为

大家好,因为我是asp.NETC的新手,我需要长者的帮助

有一个包含以下列的表:

ID int unique not null
Title varchar(250) not null
Username varchar(100) not null
Datetime datetime not null
Shortviews varchar(500) not null
Fullviews varchar(1000) not null
Photo image not null
我已经成功地将页面编码为在该表中插入数据,现在我想在页面上显示它,我使用repeater data控件仅显示其标题,并将其放入下面的属性代码中

   <asp:Repeater ID="article_rep" runat="server" 
        onitemcommand="article_rep_ItemCommand">
        <itemtemplate>
            <ul class="list1">
                <li><a href="#"><%# Eval("Title")%></a></li>
            </ul>
        </itemtemplate>
    </asp:Repeater>
它显示最后五行的表记录,我希望当我单击任何标题时,它会在另一个页面上显示与该标题相关的其余列信息(我单击了该标题),该页面将是Details.aspx


我知道这对老年人来说很简单,但我被它打动了。请帮助我,提前谢谢。我必须在Details.aspx上编码的内容以及我必须在Details.aspx.cs上编码的内容.cs文件中的组件id错误。将world_rep更改为article_rep。其他内容看起来不错

protected void Page_Load(object sender, EventArgs e)
{
    string strConnString = ConfigurationManager.ConnectionStrings["LgnConnectionString"].ConnectionString;
string str;
    SqlCommand com;
    SqlConnection con = new SqlConnection(strConnString);
    con.Open();
    str = "select top 5 Title from table ORDER BY Datetime DESC";
    com = new SqlCommand(str, con);
    SqlDataReader reader;
    reader = com.ExecuteReader();
    //world_rep.DataSource = reader;
    //world_rep.DataBind();
    article_rep.DataSource = reader;
    article_rep.DataBind();
    con.Close();
}
如果您需要详细信息页面,请添加如下链接

<asp:Repeater ID="article_rep" runat="server" 
    onitemcommand="article_rep_ItemCommand">
    <itemtemplate>
        <ul class="list1">
            <li><a href="details.asp?id=<%# Eval("ID")%>"><%# Eval("Title")%></a></li>
        </ul>
    </itemtemplate>
</asp:Repeater>
protected void Page_Load(object sender, EventArgs e)
{
    string strConnString = ConfigurationManager.ConnectionStrings["LgnConnectionString"].ConnectionString;
    string str;
    int requestId = int.Parse(Request.QueryString["id"]); //Get the ID
    SqlCommand com;
    SqlConnection con = new SqlConnection(strConnString);
    con.Open();
    str = "select * from table where ID=@ID";
    com = new SqlCommand(str, con);
    com.parameters.addWithValue("@ID", requestId); //add ID parameter to query
    SqlDataReader reader;
    reader = com.ExecuteReader();
    myDetailsview.DataSource = reader;
    myDetailsview.DataBind();
    con.Close();
}
根据自组织Detailsview组件,使用以下代码

//Define the class to hold the Tite property  values.
public class RepeaterTitle
{
     public string Title { get; set; }
}



  string strConnString = ConfigurationManager.ConnectionStrings["LgnConnectionString"].ConnectionString;
    string str;
    SqlCommand com;
    SqlConnection con = new SqlConnection(strConnString);
    con.Open();
    str = "select top 5 Title from table ORDER BY Datetime DESC";
    com = new SqlCommand(str, con);
    SqlDataReader reader;
    reader = com.ExecuteReader();
    List<RepeaterTitle> TitleLIst = new List<RepeaterTitle>();
    while (reader.Read())
    {
        RepeaterTitle oTitle = new RepeaterTitle();
        oTitle.Title = reader.GetValue(0).ToString();
        TitleLIst.Add(oTitle);
    }
    article_rep.DataSource = TitleLIst;
    article_rep.DataBind();
    con.Close();

那么,您的问题是什么?先生,问题是:当我点击标题链接时,获取details.aspx页面上所有记录的过程是什么。这就像新闻一样,当我们点击新闻网站上的新闻时,它会打开一个新页面,其中包含该新闻的详细信息,我们点击了早期的OK,但你有什么问题?你试过什么了吗?先生,这不是我请求帮助的问题。我如何在另一个页面上显示其余的详细信息。aspx,它就像新闻一样,当我们单击新闻中的新闻网站时,它会打开一个新页面,其中包含该新闻的详细信息,我需要一些帮助。我需要在details.aspx页面中编写什么代码,以及details.aspx.cs中代码背后的内容
//Define the class to hold the Tite property  values.
public class RepeaterTitle
{
     public string Title { get; set; }
}



  string strConnString = ConfigurationManager.ConnectionStrings["LgnConnectionString"].ConnectionString;
    string str;
    SqlCommand com;
    SqlConnection con = new SqlConnection(strConnString);
    con.Open();
    str = "select top 5 Title from table ORDER BY Datetime DESC";
    com = new SqlCommand(str, con);
    SqlDataReader reader;
    reader = com.ExecuteReader();
    List<RepeaterTitle> TitleLIst = new List<RepeaterTitle>();
    while (reader.Read())
    {
        RepeaterTitle oTitle = new RepeaterTitle();
        oTitle.Title = reader.GetValue(0).ToString();
        TitleLIst.Add(oTitle);
    }
    article_rep.DataSource = TitleLIst;
    article_rep.DataBind();
    con.Close();