Dynamic LinkButton Control

R

RSB

Hi Everyone,

I have a collection of items and i am generating a Dynamic Table based on
this Collection and i am also adding a Remove Linkbutton at the End for Each
Row. I have created a function called GenerateList and i call this in the
OnPreRender
Now every thing is fine but i am not able to Capture the Event for the
"Remove This"
all i want to do is remove the selected item from the collection..


Please help

Here is the COde..





public void GenerateList(MyCollection myCollection ) {

Table tblMain = new Table();
TableRow row = new TableRow();
TableCell cell = new TableCell() ;
addGridTableCell(row, " Student#",3,"#AAAADD","SmallDatalabel");
addGridTableCell(row, "Name",8,"#AAAADD","SmallDatalabel");
addGridTableCell(row, "Address",50,"#AAAADD","SmallDatalabel");
addGridTableCell(row, "Phone",13,"#AAAADD","SmallDatalabel");
tblMain.Rows.Add(row);
int i=0;
myCollectionItem s;
LinkButton LinkBut ;
foreach( System.Collections.DictionaryEntry e in myCollection ) {

s = (myCollectionItem) e.Value;

i++;
row = new TableRow();
addGridTableCell(row, i.ToString(),3,"#FFFFFF","");
addGridTableCell(row, s.Name.ToString () ,8,"#FFFFFF"," ");
addGridTableCell(row, s.Address.ToString(),50,"#FFFFFF"," ");
addGridTableCell(row, s.Phone.ToString () ,13,"#FFFFFF"," ");

cell = new TableCell() ;
cell.Width = Unit.Percentage(8.0);
cell.BackColor = Color.FromName("#FFFFFF");
LinkBut = new LinkButton();
LinkBut.ID = e.Key.ToString();
LinkBut.Text = "Remove this";
LinkBut.Click += new System.EventHandler(this.LinkBut_Click);
cell.Controls.Add(LinkBut);

row.Cells.Add (cell);

tblMain.Rows.Add(row);
}
}


public static void addGridTableCell(TableRow row, string cellText, double
cellWidth, string bgColor, string clsName){
TableCell cell = new TableCell() ;
cell.Text = cellText;
cell.Width = Unit.Percentage(cellWidth);
cell.BackColor = Color.FromName(bgColor);
cell.CssClass = clsName;
//cell.Wrap = false;
row.Cells.Add (cell);
}
 
J

John Saunders

RSB said:
Hi Everyone,

I have a collection of items and i am generating a Dynamic Table based on
this Collection and i am also adding a Remove Linkbutton at the End for Each
Row. I have created a function called GenerateList and i call this in the
OnPreRender
Now every thing is fine but i am not able to Capture the Event for the
"Remove This"
all i want to do is remove the selected item from the collection..

Had you considered using a DataGrid instead of your dynamic table? You could
use a HyperLinkColumn for your Remove link and handle the ItemCommand event
of the DataGrid to tell you which Remove link had been clicked.

Alternatively, could you generate your table earlier than PreRender? Then
you'd be able to use the Click event of your LinkButton.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top