Click here to Skip to main content
15,906,335 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
I create html table using c# code to generate table
Now how can i allow paging to my table ?
My code is
XML
html.Append("<table border="1">");

        int itemCount = 0;
        StringBuilder sbImageRow = new StringBuilder();
        StringBuilder sbNameRow = new StringBuilder();
        foreach (DataRow row in dt.Rows)
        {
            itemCount++;
            int windex = row["Image"].ToString().IndexOf("/");
            sbImageRow.Append("<td><img src='" + row["Image"].ToString().Substring(windex) + "' height='60' width='60' </></td>");
            sbNameRow.Append("<td>" + row["Name"] + "</td>");

            if(itemCount % 3 == 0)
            {
                //Add Image Row
                html.Append("<tr>");
                html.Append(sbImageRow.ToString());
                html.Append("</tr>");

                //Add Name Row
                html.Append("<tr>");
                html.Append(sbNameRow.ToString());
                html.Append("</tr>");

                //Reset values for next group
                itemCount = 0;
                sbImageRow = new StringBuilder();
                sbNameRow = new StringBuilder();
            }
        }

        //Check if some of the data hasn't been added to table yet
        if(itemCount != 0)
        {
            //Pad with empty cells if needed
            for(int i = itemCount; i < 3; i++)
            {
                sbImageRow.Append("<td></td>");
                sbNameRow.Append("<td></td>");
            }

            //Add Image Row
            html.Append("<tr>");
            html.Append(sbImageRow.ToString());
            html.Append("</tr>");

            //Add Name Row
            html.Append("<tr>");
            html.Append(sbNameRow.ToString());
            html.Append("</tr>");
        }

        html.Append("</table>");
Posted

1 solution

 
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