Re: Click event of button control on a tablecell of asp.net Table

S

Svein Terje Gaup

The problem seems to be that you are trying to catch an event that was
raised from within another control. The Repeater control and the DataList
control has support for catching such events through the ItemCommand event.
This is not provided by the asp table control. There seems to be no way
provided for this purpose; sombody please correct me if I'm wrong.

I suggest you use the Repeater control in stead of the Table control. The
following article explains how to use the ItemCommand event for the Repeater
control:
http://msdn.microsoft.com/library/d...iwebcontrolsrepeaterclassitemcommandtopic.asp

Not sure if this helps,

Sincerely
Svein Terje Gaup

(Type your message here)
I have an asp.net application. In response to a button(on the form) click
event I create a asp.net table and create rows and column. These rows and
coulmn's data I extract from dataset and fill the contnet of columns and
rows of the table. As I want to have each row vertically displayed, I use
asp.table control instead of DataGrid control. At the end of each row I have
embeded a button control in last column. Code is as follwos:

private void btnRunTcl_Click(object sender, System.EventArgs e)
{
DataSet ds = Test();
int counter = 0;
//loop over columns in a row
foreach(DataColumn dc in ds.Tables[0].Columns)
{
TableRow trow = new TableRow();
TableCell tcellcolname;

tcellcolname = new TableCell();
tcellcolname.Text = dc.ColumnName;
trow.BackColor = System.Drawing.Color.Beige;
tcellcolname.BackColor = System.Drawing.Color.AliceBlue;
//add column name to row
tcellcolname.Controls.Add(new LiteralControl(dc.ColumnName.ToString()));
trow.Cells.Add(tcellcolname);

TableCell tcellcoData;
//count the nr of columns to be added as rows
int cnt = ds.Tables[0].Columns.Count;
//loop over rows in table
foreach(DataRow dr in ds.Tables[0].Rows)
{
tcellcoData = new TableCell();
//add column content to row
tcellcoData.Controls.Add(new LiteralControl(dr[dc.ColumnName].ToString()));
trow.Cells.Add(tcellcoData);
counter++;
//after last row(column) add button
if(cnt == counter)
{
btn.ID="btnViewDetails";
btn.Font.Bold=true;
btn.Text="ViewDetails";

TableCell tcellcoData1 = new TableCell();
tcellcoData.Controls.Add(btn);
trow.Cells.Add(tcellcoData1);
}
}
//add each row to the table
DocItemTable.Rows.Add(trow);
}

this.btnExport.Visible = true;
this.btnPrint.Visible = true;
this.lblQryRslt.Visible = true;
}


I have wired the button click event of this buttone(button named->
btnViewDetails in above code) in InitializeComponent()as follwos:

this.btn.Click +=new System.EventHandler(this.btnViewDetails_Click);

but somehow this button event does not fire up when the table is displyed
and button in the last coulmn is clicked.
Any suggestion as to why this event does not fire up?

I even tried to put above event in "override protected void OnInit(EventArgs
e)", but it does not show any result.

Thanks for any help in advance.
 

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

Members online

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top