使用超链接控件显示来自数据库asp.net c#的数据 [英] Display Data from database asp.net c# with hyperlink control

查看:87
本文介绍了使用超链接控件显示来自数据库asp.net c#的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,因为我是asp.net C的新手#我需要老年人的帮助



有一个表格包含以下栏目:



Hello everyone as I am new in asp.net C# I need some help from seniors

There is a table with following columns:

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





我已经成功编写了用于在此表中插入数据的页面现在我想在页面上显示它,我使用转发器数据控件来显示其标题并将其放在属性中代码如下





I have successfully coded the page for inserting data in this table Now I want to display it on the page, I used repeater data control to display its Title only and put it in attribute the code is below

<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>



我在代码后面选择了以下代码的数据




Behind the code I selected Data with following code

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();
    con.Close();
}







显示最后五行的表记录,我想要的时候我点击任何标题,它显示与该标题相关的其余列信息,我点击了,在另一个页面上将是Details.aspx



我知道它是对于老年人来说简单易行,但我对它有所帮助,请提前帮助我。我需要在Details.aspx上进行编码以及我需要在Details.aspx.cs上进行编码




it display the table records for last five rows, I want that when I click on any title it display the rest of columns information associated with that Title, which I clicked, on another page that will be Details.aspx

I know it is simple and easy for seniors but I get struck on it please help me, thanks in advance. What I will have to code on Details.aspx and what will I have to code on Details.aspx.cs

推荐答案

CodeProject常见问题系列1:ASP.NET GridView [ ^ ]可以给你一些建议。
CodeProject Frequently Asked Questions Series 1: The ASP.NET GridView[^] could give you some suggestions.


这篇关于使用超链接控件显示来自数据库asp.net c#的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆