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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T15:21:16+00:00 2026-06-16T15:21:16+00:00

I have created a function which displays a bus seat layout, dynamically. Now after

  • 0

I have created a function which displays a bus seat layout, dynamically. Now after adding all this dynamically created table and cells into a tag, I want to know which imagebutton was clicked.I have also mentioned proper ID to each imagebutton in cell.

public void DisplaySeatLayout(ListBus _listBus) {
        //fetching data from database     
        SeatBUS _seatBUS = new SeatBUS();
        DataTable dt = _seatBUS.GetAllSeatByBusRouter(_listBus);

        //Layout generation code    
        ImageButton img ;
        HtmlTable table = new HtmlTable();
        table.Attributes.Add("runat", "server");
        table.Attributes.Add("id", "LayoutTable");

        HtmlTableRow [] tr = new HtmlTableRow[] { new HtmlTableRow(), new HtmlTableRow(), new HtmlTableRow(),new HtmlTableRow(),new HtmlTableRow()};
        HtmlTableCell tc = null;
        int SeatNo=0;
        //Getting Total no of seats.
        int MaxSeatNo = dt.Rows.Count;
        //Iterating datatable

            //Displaying labels for displaying column names in the table
            for (int columnCounter = 0; columnCounter < 8; columnCounter++){

                for (int rowCounter = 0; rowCounter < 5; rowCounter++){

                    if (SeatNo < MaxSeatNo){
                            if (rowCounter == 2 && columnCounter < 7){
                                tc = new HtmlTableCell();
                                Label lbl = new Label();
                                lbl.Text = "";
                                lbl.ID = "lbl " + rowCounter.ToString() + columnCounter.ToString();

                                tc.Controls.Add(lbl);
                                tr[rowCounter].Controls.Add(tc);
                                //reducing seat number for sake of sequence.

                            }
                            else{
                                //adding label in each cell.
                                tc = new HtmlTableCell();
                                Label lbl = new Label();
                                lbl.Text = dt.Rows[SeatNo]["NumberSeat"].ToString();
                                lbl.ID = "lbl " + rowCounter.ToString() + columnCounter.ToString();

                                tc.Controls.Add(lbl);
                                //adding imagebutton in each cell . 
                                img = new ImageButton();
                                img.Attributes.Add("type", "image");
                                img.Attributes.Add("id", rowCounter.ToString());
                                img.CssClass = "seatRightMostRow1";
                                img.ImageUrl = "../Images/available_seat_img.png";
                                img.ID = dt.Rows[SeatNo]["NumberSeat"].ToString();
                                img.Click += new ImageClickEventHandler(Imagebutton_Click);
                                tc.Controls.Add(img);
                                tr[rowCounter].Controls.Add(tc);
                                SeatNo++;
                            }
                    }//SeatNo < MaxSeatNo
                  table.Controls.Add(tr[rowCounter]);
                }
                seatArranngement.Controls.Add(table);
            }

}

this is complete code after suggestion.
function that is displaying dynamic table is inside Page_load

     protected void Page_Load(object sender, EventArgs e)
     {
      _listBusBUS = new ListBusBUS();
       _routerBUS = new RouterBUS();
      _listBus = new ListBus();
      _promoteBUS = new PromoteBUS(); 

       if (!Page.IsPostBack)
      {
          LoadData();

      }
      DisplaySeatLayout();
    }

Also here i have copied code in prerender

     protected override void OnPreRender(EventArgs e)
     {
    if (MultiView1.ActiveViewIndex == 1)
    {
        int listBusID = int.Parse(hdlListBusID.Value.ToString());
        _listBus = _listBusBUS.GetAllListBusById(listBusID);

        litListBusID.Text = _listBus.ListBusID.ToString();
        litRouterID.Text = _listBus.RouterID.ToString();
        litArrival.Text = _listBus.Arrival.ToString();
        litDeparture.Text = _listBus.Departure.ToString();
        litPrice.Text = _listBus.Price.ToString();
    }
    else if (MultiView1.ActiveViewIndex == 2)
    {

        //original code starts from here
        litListBusIDS.Text = litListBusIDS.Text;
        litRouterIDS.Text = litRouterID.Text;
        litArrivalS.Text = litArrival.Text;
        litDepartureS.Text = litDeparture.Text;
        litSeat.Text = hdlSeat.Value;// chkSeat.SelectedItem.Text;


        litPrices.Text = litPrice.Text;
        //hdlSeat.Value = chkSeat.SelectedItem.Text.ToString();
    }
    else if (MultiView1.ActiveViewIndex == 3)
    {
        litCustomerNameStep4.Text = txtcustomername.Text;
        litSeatStep4.Text = litSeat.Text;
        litPriceStep4.Text = litPrices.Text;
    }
    base.PreRender(e);
}

Also, layout is getting created twice if i click on any imagebutton.

  • 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-16T15:21:18+00:00Added an answer on June 16, 2026 at 3:21 pm

    All you have to do is get the value that you already placed inside the “id” attribute.

    You can do this inside the Imagebutton_Click even you created:

     protected void Imagebutton_Click(object sender, EventArgs e)
     {
            ImageButton b = sender as ImageButton;
            string id = b.Attributes["id"]; // Returns the id
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created an utility function which I include in almost all Javascript code
I am developing an android application. Now i have created one function which create
I have a table created from jquery datatable which displays like above: like you
I have a div which which displays dynamically created tables (In a asp.net repeater
I have created a simple GUI which includes a JTable. This table may be
I have created a function which gets an encoded string (possibly UTF-16 not sure)
I have created a JS function which executes fine when it's included an the
Using xlwDotNet, I have created a simple function which returns one number. Sometimes, something
I have created a add input field function which is working fine. I would
I have a function which creates an object of values, but im getting this

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.