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

  • Home
  • SEARCH
  • 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 am new to NH. I have a table in a legacy DB that
What I have are two tables: mark_notifications mark_notifications_options The mark_notifications table contains rows of
I'm trying to make a table showing different values in each cell, and depending
I have been playing with Javascript to find out how i can dynamically create
I have some data in SQL Server as: att1 att2 att3 att4 att5 ...
I have two tables and I want to use the database to enforce a
i have a dataset which im using to calculate some sales figures, this data
I'm working on a fairly simple ticket managment system. I want to keep a
String[] items = new String[10]; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); //
I originally wrote my Ruby on Rails application for one client. Now, I am

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.