How to dynamically insert rows into a Table control? - DOTNET

This is a discussion on How to dynamically insert rows into a Table control? - DOTNET ; I am new to the asp.net Table web control. I am using it to customize my presentation of data. I cannot implement the idea with DataGrid or GridView. Basically, I would like to have something like what is shown in ...

+ Reply to Thread
Results 1 to 7 of 7

How to dynamically insert rows into a Table control?

  1. Default How to dynamically insert rows into a Table control?

    I am new to the asp.net Table web control. I am using it to customize
    my presentation of data. I cannot implement the idea with DataGrid or
    GridView.

    Basically, I would like to have something like what is shown in the
    following PNG image.

    http://farm3.static.flickr.com/2183/...acb1ed9b_o.png

    I know how to dynamically add rows to the end of the table, but how do
    I insert rows right after some particular row?

    I guess the problem boils down to getting the current row index. How
    do we get the current row index of a dynamically built Table? Thank
    you.


  2. Default Re: How to dynamically insert rows into a Table control?

    Two ways to do that:

    You can add all rows at once and show/hide those brea-down detail rows by
    toggling their Visible property;

    or

    You can inset those break-down detail rows dynamically when needed, using
    TableRowCollection.AddAt(index, TableRow).


    "gnewsgroup" <gnewsgroup@gmail.com> wrote in message
    news:1193784389.028559.211890@22g2000hsm.googlegroups.com...
    >I am new to the asp.net Table web control. I am using it to customize
    > my presentation of data. I cannot implement the idea with DataGrid or
    > GridView.
    >
    > Basically, I would like to have something like what is shown in the
    > following PNG image.
    >
    > http://farm3.static.flickr.com/2183/...acb1ed9b_o.png
    >
    > I know how to dynamically add rows to the end of the table, but how do
    > I insert rows right after some particular row?
    >
    > I guess the problem boils down to getting the current row index. How
    > do we get the current row index of a dynamically built Table? Thank
    > you.
    >



  3. Default Re: How to dynamically insert rows into a Table control?

    On Oct 30, 7:10 pm, "Norman Yuan" <NoAddr...@NoEmail.fake> wrote:
    > Two ways to do that:
    >
    > You can add all rows at once and show/hide those brea-down detail rows by
    > toggling their Visible property;
    >
    > or
    >
    > You can inset those break-down detail rows dynamically when needed, using
    > TableRowCollection.AddAt(index, TableRow).
    >


    OK, thank you. How do I get the row index when the image button is
    clicked? In other words, how do I know in which row the click event
    takes place?


  4. Default Re: How to dynamically insert rows into a Table control?

    On Oct 30, 7:10 pm, "Norman Yuan" <NoAddr...@NoEmail.fake> wrote:
    > Two ways to do that:
    >
    > You can add all rows at once and show/hide those brea-down detail rows by
    > toggling their Visible property;
    >
    > or
    >
    > You can inset those break-down detail rows dynamically when needed, using
    > TableRowCollection.AddAt(index, TableRow).
    >


    On Oct 30, 7:10 pm, "Norman Yuan" <NoAddr...@NoEmail.fake> wrote:
    > Two ways to do that:
    >
    > You can add all rows at once and show/hide those brea-down detail rows by
    > toggling their Visible property;
    >
    > or
    >
    > You can inset those break-down detail rows dynamically when needed, using
    > TableRowCollection.AddAt(index, TableRow).
    >


    OK, thanks again. In a GridView, we can usually get the row index of
    a click event by attaching the Container.DataItemIndex to the
    CommandArgument of the Button. For example,

    <asp:TemplateField HeaderText="Title" >
    <ItemTemplate>
    <asp:Label ID="Label1" runat="server">
    <%# Container.DataItemIndex + 1 %>. <%#
    Eval("Title") %>
    </asp:Label>
    </ItemTemplate>
    </asp:TemplateField>

    Can we get the row index like so for a Table control?


  5. Default Re: How to dynamically insert rows into a Table control?


    Hi,

    You can get index of currently selected row.
    In below example, I have 1 Html table control,I have given it's id
    value='tbl' and runat='server', so that I can use it's properties like
    other control's properties.

    protected void Button2_Click(object sender, EventArgs e)
    {
    int index=0;
    for (int i = 0; i < tbl.Rows.Count; i++)
    {
    Button btn =
    (Button)tbl.Rows[i].Cells[0].FindControl("btn");
    if (btn != null)
    {
    index = i;
    break;
    }
    }
    }

    You can use any contorl instead Button.


    Regards,
    Mansi Shah.

    *** Sent via Developersdex http://www.developersdex.com ***

  6. Default Re: How to dynamically insert rows into a Table control?

    On Oct 31, 1:52 am, Mansi Shah <ma...@devdex.com> wrote:
    > Hi,
    >
    > You can get index of currently selected row.
    > In below example, I have 1 Html table control,I have given it's id
    > value='tbl' and runat='server', so that I can use it's properties like
    > other control's properties.
    >
    > protected void Button2_Click(object sender, EventArgs e)
    > {
    > int index=0;
    > for (int i = 0; i < tbl.Rows.Count; i++)
    > {
    > Button btn =
    > (Button)tbl.Rows[i].Cells[0].FindControl("btn");
    > if (btn != null)
    > {
    > index = i;
    > break;
    > }
    > }
    > }
    >
    > You can use any contorl instead Button.
    >
    > Regards,
    > Mansi Shah.
    >
    > *** Sent via Developersdexhttp://www.developersdex.com***


    Thank you very much. I tried your code, for my ImageButton click
    event, and I get an error as follows:

    Multiple controls with the same ID 'imgbtn' were found. FindControl
    requires that controls have unique IDs.

    The problem is that everything including the ImageButton in my Table
    control is dynamically constructed in the code-behind. So, I don't
    know the ID of the ImageButton.

    Any other idea about how to get the row index of the clicked row in a
    Table control? Thanks.


  7. Default Re: How to dynamically insert rows into a Table control?

    On Oct 31, 9:49 am, gnewsgroup <gnewsgr...@gmail.com> wrote:
    > On Oct 31, 1:52 am, Mansi Shah <ma...@devdex.com> wrote:
    >
    >
    >
    > > Hi,

    >
    > > You can get index of currently selected row.
    > > In below example, I have 1 Html table control,I have given it's id
    > > value='tbl' and runat='server', so that I can use it's properties like
    > > other control's properties.

    >
    > > protected void Button2_Click(object sender, EventArgs e)
    > > {
    > > int index=0;
    > > for (int i = 0; i < tbl.Rows.Count; i++)
    > > {
    > > Button btn =
    > > (Button)tbl.Rows[i].Cells[0].FindControl("btn");
    > > if (btn != null)
    > > {
    > > index = i;
    > > break;
    > > }
    > > }
    > > }

    >
    > > You can use any contorl instead Button.

    >
    > > Regards,
    > > Mansi Shah.

    >
    > > *** Sent via Developersdexhttp://www.developersdex.com***

    >
    > Thank you very much. I tried your code, for my ImageButton click
    > event, and I get an error as follows:
    >
    > Multiple controls with the same ID 'imgbtn' were found. FindControl
    > requires that controls have unique IDs.
    >
    > The problem is that everything including the ImageButton in my Table
    > control is dynamically constructed in the code-behind. So, I don't
    > know the ID of the ImageButton.
    >
    > Any other idea about how to get the row index of the clicked row in a
    > Table control? Thanks.


    By the way, this is how I construct the table:

    foreach (DataRow dr in dt.Rows)
    {
    TableCell tc0 = new TableCell();
    TableCell tc1 = new TableCell();
    TableCell tc2 = new TableCell();
    TableCell tc3 = new TableCell();

    ImageButton ib = new ImageButton();
    ib.ImageUrl = "~/Images/plus.GIF";
    ib.Click += new
    ImageClickEventHandler(ib_Click);

    tc0.Controls.Add(ib);
    tc1.Text = dr["Year"].ToString();
    tc2.Text = dr["Import Total"].ToString();
    tc3.Text = dr["Export Total"].ToString();

    TableRow tr = new TableRow();
    tr.Cells.Add(tc0);
    tr.Cells.Add(tc1);
    tr.Cells.Add(tc2);
    tr.Cells.Add(tc3);

    tbl1.Rows.Add(tr);
    }


+ Reply to Thread

Similar Threads

  1. Adding rows to html table dynamically
    By Application Development in forum DOTNET
    Replies: 3
    Last Post: 09-21-2007, 08:18 AM
  2. Dynamically adding rows to table web server control
    By Application Development in forum DOTNET
    Replies: 2
    Last Post: 07-26-2007, 08:04 AM
  3. Adding rows dynamically
    By Application Development in forum Javascript
    Replies: 1
    Last Post: 06-07-2007, 02:08 PM
  4. counting rows in a table with split rows?
    By Application Development in forum Adobe Indesign
    Replies: 5
    Last Post: 01-09-2007, 01:46 AM
  5. Dynamically Created Table Rows, Accessing Values
    By Application Development in forum Javascript
    Replies: 1
    Last Post: 04-28-2006, 01:24 PM