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 9089561
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T22:10:45+00:00 2026-06-16T22:10:45+00:00

I am creating a C# application which fetches data from a database, and dynamically

  • 0

I am creating a C# application which fetches data from a database, and dynamically creates 5 textBoxes and one button in a single row.

The number of rows present in the database equals the number of rows of textBoxes and buttons that are created.

I could successfully create the rows of textBoxes and buttons, the textBoxes are even capable of displaying data that is being fetched from the database.

My trouble however is that the button that is generated, does nothing when clicked, now that is not unexpected since i haven’t created a handler to handle the click event. But i am confused on how to dynamically create the click even handler for the buttons that are again generated dynamically.

Below is the code sample that generated the textBoxes and buttons.

for (int i = 3; i <= count; i++)
{
    com.Parameters[0].Value = i;
    using (SqlCeDataReader rd = com.ExecuteReader())
    if (rd.Read())
    {
        pname = (rd["pname"].ToString());
        cname = (rd["cname"].ToString());
        budget = (rd["budget"].ToString());
        advance = (rd["advance"].ToString());
        ddate = (rd["ddate"].ToString());

        TextBox tobj = new TextBox();
        tobj.Location = new Point(10, (40 + ((i - 2) * 20)));
        tobj.Tag = 1;
        tobj.Text = pname;
        tobj.AutoSize = false;
        tobj.Width = 150;
        tobj.ReadOnly = true;
        this.Controls.Add(tobj);

        TextBox tobj1 = new TextBox();
        tobj1.Location = new Point(160, (40 + ((i - 2) * 20)));
        tobj1.Tag = 2;
        tobj1.Text = cname;
        tobj1.AutoSize = false;
        tobj1.Width = 150;
        tobj1.ReadOnly = true;
        this.Controls.Add(tobj1);

        TextBox tobj2 = new TextBox();
        tobj2.Location = new Point(310, (40 + ((i - 2) * 20)));
        tobj2.Tag = 3;
        tobj2.Text = budget;
        tobj2.AutoSize = false;
        tobj2.Width = 100;
        tobj2.ReadOnly = true;
        this.Controls.Add(tobj2);

        TextBox tobj3 = new TextBox();
        tobj3.Location = new Point(410, (40 + ((i - 2) * 20)));
        tobj3.Tag = 4;
        tobj3.Text = advance;
        tobj3.AutoSize = false;
        tobj3.Width = 100;
        tobj3.ReadOnly = true;
        this.Controls.Add(tobj3);

        TextBox tobj4 = new TextBox();
        tobj4.Location = new Point(510, (40 + ((i - 2) * 20)));
        tobj4.Tag = 5;
        tobj4.Text = ddate;
        tobj4.AutoSize = false;
        tobj4.Width = 100;
        tobj4.ReadOnly = true;

        int due = 0;
        due = int.Parse(ddate);
        if (due < 5)
        {
             tobj4.BackColor = System.Drawing.Color.Red;
        }

        this.Controls.Add(tobj4);

        Button button = new Button();
        button.Left = 620;
        button.Tag = i;
        button.Height = 20;
        button.Text = "Details";
        button.Top = (40 + ((i - 2) * 20));
        this.Controls.Add(button);  
    }
}

Please give me some ideas on how to generate the click event handler.

  • 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-06-16T22:10:46+00:00Added an answer on June 16, 2026 at 10:10 pm

    Answer part:

    Add this:

    button.Tag = i;
    button.Click += handleTheClick;
    
    ...
    
    private void handleTheClick(object sender, EventArgs e){
        Button btn = sender as Button;
        int row = (int)btn.Tag;
    }
    

    Un-answer:

    You should reconsider your design. Including coordinates in your data processing code is a really bad idea in 2013, try using ListView, ListBox, GridView or better – switch to WPF.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am creating iphone application which will require data from .NET web services. I
I'm creating an android application which should parse a Json from a file or
I am creating an XML based application in which I have to fetch data
I'm creating a flash application which loads in some XML which is generated dynamically
I am creating application which stores the users financial information in a sqlite database.
I am creating one application which convert text into speech in Indian English. I
I am creating an application which displays the market data and uses it in
I'm creating an application which uses venues and categories from Foursquare. In order to
I am creating one application which requires recording voice and then funny voice will
I am currently creating application which requires Current Time From the Country. I have

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.