| View previous topic :: View next topic |
| Author |
Message |
Abhi
Joined: 21 Aug 2007 Posts: 145
|
Posted: Mon Aug 11, 2008 5:40 am Post subject: How to add Link Button to Table Control in asp.net |
|
|
hi experts,
I want to add a link button to asp.net table control. any body let me the code for this...
Thanking you in advance.
regards,
abhi. |
|
| Back to top |
|
 |
craig
Joined: 24 Aug 2007 Posts: 36
|
Posted: Mon Aug 11, 2008 5:52 am Post subject: |
|
|
hi all,
here is the code to add a linkButton to a table control.
Code :
int numberOfItems = 12; // for example
int numberOfCells = 5;
// Determine how many rows it will have
int count = numberOfItems / numberOfCells;
if (numberOfItems % numberOfCells != 0)
count++;
for (int j = 0; j < count; j++)
{
TableRow row = new TableRow();
for (int i = 0; i < numberOfCells; i++)
{
TableCell cell = new TableCell();
// Can be a LinkButton or whatever... your choice!
LinkButton lnk = new LinkButton();
lnk.ID = "myLNK";
lnk.Text = "Item "+j.ToString() + i.ToString();
// add whatever properties you want for the LinkButtons
cell.Controls.Add(lnk);
row.Cells.Add(cell);
}
// assuming you have an ASP.NET Table control in your page with ID set to 'tblMenu'
tblMenu.Rows.Add(row);
}
here "tblMenu" is ID of Table Control . Copy and Paste the above code.
regards,
craig |
|
| Back to top |
|
 |
|