Tuesday, 20 August 2013

Creating table 3*3 based on elements number from asp.net codebehind

Creating table 3*3 based on elements number from asp.net codebehind

public void GetTableData(int index, List<SubCategory> subcatList, int
PageSize, string type)
{
int count = 0;
int number = 0;
lowerbound = (index - 1) * PageSize;
upperbound = (index * PageSize) - 1;
IEnumerable<SubCategory> take = subcatList.Skip((index - 1) *
PageSize).Take(PageSize);
int numberOfRows = 3;
int numberofColumns = take.Count() / numberOfRows + 1;
number = take.Count();
for (int row = 0; row < 3; row++)
{
HtmlTableRow tblrows = new HtmlTableRow();
bool broke = false;
for (int col = 0; col < 3; col++)
{
if (count >= take.Count())
{
broke = true;
break;
}
HtmlTableCell tblcells = new HtmlTableCell();
HtmlGenericControl span = new HtmlGenericControl("span");
System.Web.UI.HtmlControls.HtmlImage img = new
System.Web.UI.HtmlControls.HtmlImage();
base64 =
Convert.ToBase64String(take.ElementAt(count).SubCategoryImageData);
img.Src = "data:image/png;base64," + base64;
img.Alt = "base64";
HtmlAnchor a = new HtmlAnchor();
a.InnerHtml = take.ElementAt(count).SubCategoryName;
Label breakline = new Label();
breakline.Text = "<br/>";
a.HRef = "~/BrowseGamesBySubcategory.aspx?subcatid=" +
take.ElementAt(count).SubCategoryId;
tblcells.Style.Add("background-color", "#f8f8ff");
tblcells.Style.Add("text-align", "center");
// Add the control to the TableCell
span.Controls.Add(img);
tblcells.Controls.Add(span);
tblcells.Controls.Add(breakline);
tblcells.Controls.Add(a);
// Add the TableCell to the TableRow
tblrows.Cells.Add(tblcells);
count = count + 1;
}
// Add the TableRow to the Table
if (broke)
{
resttablegame.Rows.Add(tblrows);
break;
}
else
{
resttablegame.Rows.Add(tblrows);
}
}
}
I am trying to create a table of elements from code behind asp.net based
on the number of elements Conditions: At a time only 3 rows and 3 columns
can be there in the table and 9 elements in each of the cells.
My issue is when i try to populate my second page of the table say it has
11 elements 9 will be shown in the first page and rest 2 have to be shown
on the second page with table having 1 row and two columns
How do i do this? please help i am getting two rows and two columns
however it should just be 1 row and two columns

No comments:

Post a Comment