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

Discussion in 'ASP .Net' started by Svein Terje Gaup, Sep 15, 2004.

  1. 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

    "Bharat Gadhia via .NET 247" <> wrote in message
    news:...
    (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.



    --------------------------------
    From: Bharat Gadhia

    -----------------------
    Posted by a user from .NET 247 (http://www.dotnet247.com/)

    <Id>pTfno1+p80WvlmR5b/rRyA==</Id>
     
    Svein Terje Gaup, Sep 15, 2004
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Purvi T
    Replies:
    0
    Views:
    858
    Purvi T
    Oct 19, 2004
  2. Brian K. Williams

    TableCell oTableCell = new TableCell(); noWrap?

    Brian K. Williams, Apr 30, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    2,531
    Brian K. Williams
    Apr 30, 2004
  3. Amy
    Replies:
    0
    Views:
    993
  4. Max2006
    Replies:
    2
    Views:
    1,578
    Walter Wang [MSFT]
    Sep 19, 2007
  5. Replies:
    0
    Views:
    136
Loading...

Share This Page