Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3311576
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T21:53:35+00:00 2026-05-17T21:53:35+00:00

I have table with 20 to 30 rows and 3 columns. I would like

  • 0

I have table with 20 to 30 rows and 3 columns. I would like to add fourth column with buttons or something in the cell that I can click on it. And onClick event I need to get info in which row has happened this click.

Table is generated programmatically on the fly.

Can this be done and I beg for some examples.

EDIT 2:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace HelpdeskOsControl
{
    public partial class Test : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //GenerateTable(getTestData());
        }

        private List<string> getTestData()
        {
            List<string> tData = new List<string>(); 
            for (int i = 0; i < 10; i++)
            {
                tData.Add("proc" + i + "_" + new Random().Next(100) + "_" + new Random().Next(100));
            }

            return tData;
        }

        protected void btnClear_Click(object sender, EventArgs e)
        {
            for (int i = Processes.Rows.Count; i > 1; i--)
            {
                Processes.Rows.RemoveAt(i - 1);
            }
        }

        protected void btnLoad_Click(object sender, EventArgs e)
        {
            GenerateTable(getTestData());
        }

        protected void btnKill_Click(object sender, EventArgs e)
        {
            lblView.Text = ((Button)sender).ID;
        }

        private void GenerateTable(List<string> list)
        {
            int st = 0;
            foreach (string line in list)
            {
                TableRow tr = new TableRow();
                Processes.Controls.Add(tr);

                foreach(String str in line.Split('_'))
                {
                    int index = tr.Cells.Add(new TableCell());
                    tr.Cells[index].Text = str;
                }

                Button b = new Button();
                b.Text = "Kill " + st;
                b.ID = "btnKill_" + st;
                b.Click += new EventHandler(btnKill_Click);
                TableCell tc = new TableCell();
                tc.Controls.Add(b);
                tr.Cells.Add(tc);

                tr.TableSection = TableRowSection.TableBody;
                Processes.Rows.Add(tr);
                st++;
            }
            Processes.BorderStyle = BorderStyle.Solid;
            Processes.GridLines = GridLines.Both;
            Processes.BorderWidth = 2;
        }

    }
}




<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="Test.ascx.cs" Inherits="HelpdeskOsControl.Test" %>
<asp:Panel ID="Panel1" runat="server" Height="465px" Width="417px">
    <asp:Table ID="Processes" runat="server" Height="20px" Width="400px" CssClass="tablesorter">
        <asp:TableHeaderRow ID="ProcessesHeader" runat="server" 
        TableSection="TableHeader">
            <asp:TableHeaderCell ID="TableHeaderCell1" runat="server">Name</asp:TableHeaderCell>
            <asp:TableHeaderCell ID="TableHeaderCell2" runat="server">CPU</asp:TableHeaderCell>
            <asp:TableHeaderCell ID="TableHeaderCell3" runat="server">Memory</asp:TableHeaderCell>
            <asp:TableHeaderCell ID="TableHeaderCell4" runat="server"></asp:TableHeaderCell>
        </asp:TableHeaderRow>
    </asp:Table>
    <asp:Panel ID="Panel2" runat="server">
        <asp:Button ID="btnLoad" runat="server" onclick="btnLoad_Click" Text="Load" />
        <asp:Button ID="btnClear" runat="server" onclick="btnClear_Click" 
            Text="Clear" />
        <asp:Label ID="lblView" runat="server" Text="Label"></asp:Label>
    </asp:Panel>
</asp:Panel>



<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="HelpdeskOsControl._Default" %>

<%@ Register src="Test.ascx" tagname="WebUserControl" tagprefix="Test" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <p>Test Control</p>
         <Test:WebUserControl ID="Test" runat="server" />
    </div>
    </form>
</body>
</html>

Can please someone checks why this code is NOT working when I comment out GenerateTable(getTestData()); in Page_Load procedure.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T21:53:35+00:00Added an answer on May 17, 2026 at 9:53 pm

    If it is a HTMLtable generated in code behind,

    assuming this is how your code looks like,

    HtmlButton b = new HtmlButton();
    b.ClientID = "Button_" + i;
    b.Attributes.Add("onClick", "your function(this)");
    

    use the suffix part from the parameter in the method to check which butto has been click.
    Hope this helps!!
    Edit:
    You may still go with the above logic. In the click event of the button ( which appears to be common for all the buttons), you ca use the sender object and get the ID and know which button has been clicked as follows:

    protected void KillButton_Click(object sender, EventArgs e) 
    { 
        string ID = ((Button)sender).ID;
    } 
    

    and you may attach the event handler in this fashion:

    b.Click += new EventHandler(KillButton_Click);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have table of 5000+ rows and 8+ columns like, Station Lat Long Date
I have a data table with many rows and columns. How can I display
I have the following table format and would like to be able to add
My database contains empty table columns. I would like to add a character like
We have a large table (450 million rows containing 34 columns of numeric or
I have a table with ~200 million rows and ~15 columns in it. I
I have a table - xxxx_nb_lo_update_date - with a number of columns and rows
I have a table with 18 columns (all Ints) and 1040 rows. If any
i have a table with columns ID,SUBJECT,BRANCH i have select the rows which satisfies
I have a table of class players with 5 columns and 40 rows. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.