Click here to Skip to main content
15,891,748 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a DataTable but a dynamic one, each time the number of rows may be different. I want to display the rows as a result list, as the example below:

C#
//DataTable 
ID | Company | Website 
1  | Dgroup  | www.dgroup.com
2  | LIU     | www.liu.com


The result I want is like this:
HTML
<h3>Dgroup</h3>
<a href="www.dgroup.com">visit website</a>
<br/>

<h3>LIU</h3>
<a href="www.liu.com">visit website</a>


How can I do this?
Posted
Comments
King Fisher 17-May-14 8:26am    
how do you get this DataTable

you can use repeater control

ASP.NET
<asp:repeater id="Repeater1" runat="server" xmlns:asp="#unknown">
    <itemtemplate>
        <h3>
            <%# Eval("Company")%></h3>
        <a href="<%# Eval("Website")%>" target="_blank">visit website</a>
    </itemtemplate>
</asp:repeater>


C#
protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        Repeater1.DataSource = GetTable();
        Repeater1.DataBind();
    }

}
 
Share this answer
 
Comments
Nirav Prabtani 17-May-14 9:13am    
my 5+
DamithSL 17-May-14 9:35am    
thank you!
string conn = "Data Source=.;Initial Catalog=FriendsBookDB;User Id=sa;Password=win7";
        SqlConnection con = new SqlConnection(conn);
        SqlCommand cmd = new SqlCommand("select top 3 EmpId,employee from ppb",con);
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        con.Open();
        da.Fill(dt);
        hyp1.NavigateUrl = "http://" + dt.Rows[0][1];


My dt contains (Datatable):

VB
1   www.facebook.com
2   www.twitter.com
3   www.google.com
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900