0

I am trying make dynamic table from database . Table Build dynamically by inserting html table code inserting place holder to get result like Grideview.

but one insert asp control button..

Problem is in that button . that doesn't appear on page . other full table is display well

html.Append(" ");

public StringBuilder DataTableBuilder(DataSet ds)
{
    try
    {
        //Building an HTML string.
        StringBuilder html = new StringBuilder();

        //Table start.
        html.Append("<div class='row container' style='font-size:large;'> " +
                    "   <div class='col-md-12 col-sm-12'> " +
                    "       <div class='card  card-box'>  " +
                    "           <div class='card-head' >   " +
                    "           <header>New Student List</header> " +
                    "               <div class='tools'>   " +
                    "                   <a class='fa fa-repeat btn-color box-refresh' href='javascript:;'></a> " +
                    "                   <a class='t-collapse btn-color fa fa-chevron-down' href='javascript:;'></a> " +
                    "                   <a class='t-close btn-color fa fa-times' href='javascript:;'></a> " +
                    "               </div> " +
                    "           </div> " +
                    "           <div class='card-body '> " +
                    "               <div class='table-wrap' > " +
                    "                   <div class='table-responsive'> " +
                    "                       <table class='table display product-overview mb-30'  id='support_table' runat='server'> " +
                    "                           <thead >");


        DataTable dt = ds.Tables[0];
        //Building the Header row.
        html.Append("<tr>");
        foreach (DataColumn column in dt.Columns)
        {
            html.Append("<th style='text-align:center'>");
            html.Append(column.ColumnName);
            html.Append("</th>");
        }
        html.Append("<th style='text-align:center'>Edit</th> </tr> </thead> <tbody style='text-align:right'> ");

        //Building the Data rows.
        foreach (DataRow row in dt.Rows)
        {
            html.Append("<tr>");
            foreach (DataColumn column in dt.Columns)
            {
                html.Append("<td>");
                html.Append(row[column.ColumnName]);
                html.Append("</td>");
            }
            html.Append("   <td> <asp:CheckBox ID='Selected" + row["ID"].ToString() + "' runat='server' AutoPostBack='true' OnCheckedChanged='Load_data' /> </td></tr>");

       //  "<asp:button id='id" + row["ID"].ToString() + "'  data-toggle='tooltip'  runat='server' AutoPostBack='true' OnClick='Load_data'  Text='Edit' / >  ============  html.Append("    <td><a onclick='Load_data("+ row["ID"].ToString()+ ")'  data-toggle='tooltip'  runat='server' AutoPostBack='true' title='Edit'><i class='fa fa-check'></i></a></td></tr>");
        }
        html.Append("</tbody> " +
            "                               </table> " +
            "                           </div> " +
            "                       </div> " +
            "                   </div> " +
            "               </div> " +
            "           </div> " +
            "       </div>");

        return html;
    }
    catch
    {
        return null;
    }

}
4
  • html.Append(" <td> <asp:CheckBox ID='Selected" + row["ID"].ToString() + "' runat='server' AutoPostBack='true' OnCheckedChanged='Load_data' /> </td></tr>"); this code is not working Commented Jul 22, 2019 at 16:37
  • If you build html as string then you need to include rendered controls like "<input type=\"checkbox\"... /> Commented Jul 22, 2019 at 17:03
  • Possible duplicate stackoverflow.com/questions/8537947/… Commented Jul 22, 2019 at 17:04
  • You cannot render aspnet controls as a string. Commented Jul 22, 2019 at 17:33

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.