Click here to Skip to main content
15,896,606 members
Please Sign up or sign in to vote.
0.00/5 (No votes)

I have created dynamic hyperlink and fetched data from database. now i need to put those data in particular div tag. Please help me.

ASP.NET
<div  runat="server" id="bdy">
</div>


C#
protected void Page_Load(object sender, EventArgs e)
{


    MySqlCommand inscmd = new MySqlCommand("select * from category", con);
    MySqlDataAdapter a = new MySqlDataAdapter(inscmd);
        DataTable t = new DataTable();

    foreach (DataRow row in t.Rows) 
            {
                bdy.InnerHtml.Equals("<a href=\"category.aspx?refid=" + row["cid"] + "\">" + row["catname"] + "</a><br />"); 

        // bdy is div name 
                 Response.Write("<a href=\"category.aspx?refid="+row["cid"]+"\">"+row["catname"]+"</a><br />");               

           }
}
Posted
Comments
♥…ЯҠ…♥ 13-Aug-13 3:11am    
I think you can use ajax call to get data from server as json and you can render it in div tag....

We can build the hyperlink content in the loop of datarows and then assign it to the innerHTML of div.

SqlDataAdapter adapter;
DataTable dt;
string mystr;

adapter = new SqlDataAdapter("Select catid, catname from category", myconnstring);
adapter.Fill(dt);
mystr = "";

foreach (DataRow dr in dt.Rows)
{
    mystr = mystr + "<a href='category.aspx?refid=" + dr("catid") + "'>" + dr("catname") + "</a></br>";
}

mydiv.InnerHtml = mystr;
 
Share this answer
 
C#
HtmlGenericControl bdy = new HtmlGenericControl("div");

HtmlGenericControl aTag = new HtmlGenericControl("a");
aTag.Attributes.Add("href","your url");

bdy.Controls.Add(aTag);

also you should use a Panel in the html page and then  

panel.Controls.Add(bdy);
 
Share this answer
 
v2

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