Please check the below code, where I am able to generate the table dynamically from the database. But not able to display the link button inside the <td>
element.
The basic function is to generate a new <tr>
for every row in the database table with a link button added.
Aspx Code
<div style="width: 80%;" id="div_post" runat="server">
</div>
Aspx.cs Code
protected void GetvicharData()
{
try
{
Data_display dd = new Data_display();
DataTable dt = dd.disp_vichar();
string in_html = string.Empty;
int i = 0;
in_html = "<table style=\"width: 100%;\">";
foreach (DataRow dr in dt.Rows)
{
string str_build = string.Empty;
i = i + 1;
string lbDate = Convert.ToDateTime(dr["Date"]).ToString("dd-MMM-yy");
string lbTopic = dr["Topic_Name"].ToString();
string desc = dr["Description"].ToString();
string imgURL = dr["img_url"].ToString();
string textUrl = dr["txt_url"].ToString();
str_build = ret_string(lbDate, lbTopic, desc, imgURL, textUrl, i);
in_html += str_build;
}
in_html += "</table>";
div_post.InnerHtml = in_html;
}
catch (Exception ex)
{
throw ex;
}
}
public string ret_string(string lbldate, string lbltopic, string description, string imgurl, string texturl, int i)
{
try
{
StringBuilder sb = new StringBuilder();
sb.Append("<tr><td class=\"post_date\" valign=\"top\" align=\"center\">");
sb.Append("<asp:Label ID=\"lblDate\" runat=\"server\">" + lbldate + "</asp:Label>");
sb.Append("</td><td class=\"post_topic\" valign=\"top\" >");
sb.Append(" <asp:Label ID=\"lblTopic" + i + "\" runat=\"server\">" + lbltopic + "</asp:Label>");
sb.Append("</td></tr><tr>");
sb.Append("<td class=\"ShowPic\" valign=\"top\" align=\"right\" ><img src=\"" + imgurl + "\" alt=\"\" id=\"img_post\" /></td>");
sb.Append("<td class=\"ShowPost\" valign=\"top\" style=\"text-align: justify\">");
sb.Append("<asp:Panel ID=\"pnlDesc" + i + "\" runat=\"server\"><p>" + description + "</p>");
sb.Append("</asp:Panel>");
sb.Append("<div><asp:LinkButton ID=\"lnkbtn" + i + "\" runat=\"server\" Text=\"Read more...\" onclick=\"lnkbtn1_Click\" OnClientClick=\"openNewWin('" + texturl + "')\" />");
sb.Append("</asp:LinkButton></div></td></tr>");
string sbuild = sb.ToString();
return sbuild;
}
catch (Exception ex)
{
throw ex;
}
}
As I am not able to figure it out that why my link button is showing hidden when I am rendering the page in the browser.