Ask a Question related to ASP.NET Data Grid Control, Design and Development.

  1. #1

    Default adding rows

    In my DataGrid I need to have two rows of data for every bound record. I
    have successfully achieved this by adding datagrid items and cells through
    code in the "DataGrid.ItemDataBound" event. The problem is that on post back
    my added rows do not stay. Aparently one needs to recreate them each page
    request. I have read several articles that suggest building up your grid
    layout in the "DataGrid.ItemCreated" event which gets called every request.
    So I put my row adding code there but then I realized that this event gets
    called before the framework adds its default row in the grid which creates a
    problem. I need my row to be added after the framework adds the default row
    so that it can be placed below it. I can not place a row with an index after
    a row that has not been created by the framework. So for now it seems like
    the only solution is to bind the grid on every request which is a waste. Is
    there another solution.

    Perry


    Perecli Manole Guest

  2. Similar Questions and Discussions

    1. ASP.NET 2 GridView: Adding rows
      Hi How can I programatically add rows and then edit cells in C# for the ASP.NET 2 GridView? I want to create a table basically where I can...
    2. Adding more rows to one column/cell only?
      I have a basic table of three columns and 10 rows. I want to add two more rows to the last column only (it's an ordering form, and the last...
    3. Adding extra rows to a DataGrid?
      Hi everyone, I'm using a DataGrid to show records from a SQL query. The problem is, I'd really like to have two "extra" rows for every one...
    4. Adding rows to DataGrid across multiple PostBacks
      Hey all, I am very new to ASP.Net (and .Net in general), but that isn't stopping the boss from wanting to begin new projects in it. This latest...
    5. Adding rows to a Datagrid
      Jason, Thanks for the reply. Yes... it would be possible... but I also don't want to commit deletes/changes to the child records until they are...
  3. #2

    Default Re: adding rows

    Hi Perecli,

    I guess if you could put your code which adds rows to datagrid in a function
    and
    call them the Datagrid events and you need to take care of postback by
    checking for Page.IsPostBack

    Thanks
    Raghavendra

    "Perecli Manole" <Perry@argowin.com> wrote in message
    news:Ooyo88%23iEHA.2140@TK2MSFTNGP15.phx.gbl...
    > In my DataGrid I need to have two rows of data for every bound record. I
    > have successfully achieved this by adding datagrid items and cells through
    > code in the "DataGrid.ItemDataBound" event. The problem is that on post
    back
    > my added rows do not stay. Aparently one needs to recreate them each page
    > request. I have read several articles that suggest building up your grid
    > layout in the "DataGrid.ItemCreated" event which gets called every
    request.
    > So I put my row adding code there but then I realized that this event gets
    > called before the framework adds its default row in the grid which creates
    a
    > problem. I need my row to be added after the framework adds the default
    row
    > so that it can be placed below it. I can not place a row with an index
    after
    > a row that has not been created by the framework. So for now it seems like
    > the only solution is to bind the grid on every request which is a waste.
    Is
    > there another solution.
    >
    > Perry
    >
    >

    Raghavendra T V Guest

  4. #3

    Default Re: adding rows

    The code that adds rows can not be in a generic function because the rows
    need to be added in a special iterative function such as
    "DataGrid.ItemDataBound" or "DataGrid.ItemCreated". These functions are
    special in that they are called by the framework once per record and the
    framework passes in the current DataItem and RowItem being proccessed. I can
    not duplicate this behavior with a standard function call.

    Perry

    "Raghavendra T V" <raagzvb@hotmail.com> wrote in message
    news:e5T4BfBjEHA.1712@TK2MSFTNGP09.phx.gbl...
    > Hi Perecli,
    >
    > I guess if you could put your code which adds rows to datagrid in a
    > function
    > and
    > call them the Datagrid events and you need to take care of postback by
    > checking for Page.IsPostBack
    >
    > Thanks
    > Raghavendra
    >
    > "Perecli Manole" <Perry@argowin.com> wrote in message
    > news:Ooyo88%23iEHA.2140@TK2MSFTNGP15.phx.gbl...
    >> In my DataGrid I need to have two rows of data for every bound record. I
    >> have successfully achieved this by adding datagrid items and cells
    >> through
    >> code in the "DataGrid.ItemDataBound" event. The problem is that on post
    > back
    >> my added rows do not stay. Aparently one needs to recreate them each page
    >> request. I have read several articles that suggest building up your grid
    >> layout in the "DataGrid.ItemCreated" event which gets called every
    > request.
    >> So I put my row adding code there but then I realized that this event
    >> gets
    >> called before the framework adds its default row in the grid which
    >> creates
    > a
    >> problem. I need my row to be added after the framework adds the default
    > row
    >> so that it can be placed below it. I can not place a row with an index
    > after
    >> a row that has not been created by the framework. So for now it seems
    >> like
    >> the only solution is to bind the grid on every request which is a waste.
    > Is
    >> there another solution.
    >>
    >> Perry
    >>
    >>
    >
    >

    Perecli Manole Guest

  5. #4

    Default Re: adding rows

    what you need to do is add the rows to the dataset instead. whenever you
    bind, the extra rows are always there and you don't need to go thru the
    hocus pocus of postback and viewstate hell

    --
    Regards,
    Alvin Bruney
    [ASP.NET MVP [url]http://mvp.support.microsoft.com/default.aspx][/url]
    Got tidbits? Get it here... [url]http://tinyurl.com/27cok[/url]
    "Perecli Manole" <Perry@argowin.com> wrote in message
    news:Ooyo88%23iEHA.2140@TK2MSFTNGP15.phx.gbl...
    > In my DataGrid I need to have two rows of data for every bound record. I
    > have successfully achieved this by adding datagrid items and cells through
    > code in the "DataGrid.ItemDataBound" event. The problem is that on post
    > back my added rows do not stay. Aparently one needs to recreate them each
    > page request. I have read several articles that suggest building up your
    > grid layout in the "DataGrid.ItemCreated" event which gets called every
    > request. So I put my row adding code there but then I realized that this
    > event gets called before the framework adds its default row in the grid
    > which creates a problem. I need my row to be added after the framework
    > adds the default row so that it can be placed below it. I can not place a
    > row with an index after a row that has not been created by the framework.
    > So for now it seems like the only solution is to bind the grid on every
    > request which is a waste. Is there another solution.
    >
    > Perry
    >

    Alvin Bruney [MVP] Guest

  6. #5

    Default Re: adding rows

    You missunderstand my requirement. The reason I need to add a row dynamicaly
    to the grid is because my row table strucuture needs to be changed. For
    every row in the database I need two rows in the grid. First row for each
    record should have one column structure and shows half the data while the
    second row has a different column structure and shows the other half of the
    data. In edit mode I need to go back to a "signle row/single column" because
    I show an entry form in it. I have achieved this by altering the grid's
    structure in the DataBind event however I have the problem described in my
    previous post.

    Perry


    "Alvin Bruney [MVP]" <vapor at steaming post office> wrote in message
    news:u2y3qpTjEHA.3876@TK2MSFTNGP15.phx.gbl...
    > what you need to do is add the rows to the dataset instead. whenever you
    > bind, the extra rows are always there and you don't need to go thru the
    > hocus pocus of postback and viewstate hell
    >
    > --
    > Regards,
    > Alvin Bruney
    > [ASP.NET MVP [url]http://mvp.support.microsoft.com/default.aspx][/url]
    > Got tidbits? Get it here... [url]http://tinyurl.com/27cok[/url]
    > "Perecli Manole" <Perry@argowin.com> wrote in message
    > news:Ooyo88%23iEHA.2140@TK2MSFTNGP15.phx.gbl...
    >> In my DataGrid I need to have two rows of data for every bound record. I
    >> have successfully achieved this by adding datagrid items and cells
    >> through code in the "DataGrid.ItemDataBound" event. The problem is that
    >> on post back my added rows do not stay. Aparently one needs to recreate
    >> them each page request. I have read several articles that suggest
    >> building up your grid layout in the "DataGrid.ItemCreated" event which
    >> gets called every request. So I put my row adding code there but then I
    >> realized that this event gets called before the framework adds its
    >> default row in the grid which creates a problem. I need my row to be
    >> added after the framework adds the default row so that it can be placed
    >> below it. I can not place a row with an index after a row that has not
    >> been created by the framework. So for now it seems like the only solution
    >> is to bind the grid on every request which is a waste. Is there another
    >> solution.
    >>
    >> Perry
    >>
    >
    >

    Perecli Manole Guest

  7. #6

    Default Re: adding rows

    you will need to bind on every request, or you can try putting the bind code
    early in the pipeline so that it can participate in viewstate. you will have
    to look at the pipeline events to find a suitable one (prerender comes to
    mind but i'm not sure that it is early enough to participate in viewstate)

    --
    Regards,
    Alvin Bruney
    [ASP.NET MVP [url]http://mvp.support.microsoft.com/default.aspx][/url]
    Got tidbits? Get it here... [url]http://tinyurl.com/27cok[/url]
    "Perecli Manole" <Perry@argowin.com> wrote in message
    news:OF7oY9ujEHA.592@TK2MSFTNGP11.phx.gbl...
    > You missunderstand my requirement. The reason I need to add a row
    > dynamicaly to the grid is because my row table strucuture needs to be
    > changed. For every row in the database I need two rows in the grid. First
    > row for each record should have one column structure and shows half the
    > data while the second row has a different column structure and shows the
    > other half of the data. In edit mode I need to go back to a "signle
    > row/single column" because I show an entry form in it. I have achieved
    > this by altering the grid's structure in the DataBind event however I have
    > the problem described in my previous post.
    >
    > Perry
    >
    >
    > "Alvin Bruney [MVP]" <vapor at steaming post office> wrote in message
    > news:u2y3qpTjEHA.3876@TK2MSFTNGP15.phx.gbl...
    >> what you need to do is add the rows to the dataset instead. whenever you
    >> bind, the extra rows are always there and you don't need to go thru the
    >> hocus pocus of postback and viewstate hell
    >>
    >> --
    >> Regards,
    >> Alvin Bruney
    >> [ASP.NET MVP [url]http://mvp.support.microsoft.com/default.aspx][/url]
    >> Got tidbits? Get it here... [url]http://tinyurl.com/27cok[/url]
    >> "Perecli Manole" <Perry@argowin.com> wrote in message
    >> news:Ooyo88%23iEHA.2140@TK2MSFTNGP15.phx.gbl...
    >>> In my DataGrid I need to have two rows of data for every bound record. I
    >>> have successfully achieved this by adding datagrid items and cells
    >>> through code in the "DataGrid.ItemDataBound" event. The problem is that
    >>> on post back my added rows do not stay. Aparently one needs to recreate
    >>> them each page request. I have read several articles that suggest
    >>> building up your grid layout in the "DataGrid.ItemCreated" event which
    >>> gets called every request. So I put my row adding code there but then I
    >>> realized that this event gets called before the framework adds its
    >>> default row in the grid which creates a problem. I need my row to be
    >>> added after the framework adds the default row so that it can be placed
    >>> below it. I can not place a row with an index after a row that has not
    >>> been created by the framework. So for now it seems like the only
    >>> solution is to bind the grid on every request which is a waste. Is there
    >>> another solution.
    >>>
    >>> Perry
    >>>
    >>
    >>
    >
    >

    Alvin Bruney [MVP] Guest

  8. #7

    Default Re: adding rows

    Even on load was not early enough to participate in viewstate. I have tried
    this in the Initialize event and it works except the viewstate gets
    confused. Apparently the columns and row modifications I am making to the
    grid are offsetting the viewstate matching so I get same good results and
    some garbled results. The framework dows not seem to save the viewstate of
    the dynamic alterations to the grid but only of the datagrid as it thinks
    was built. The trick is not to use the built in viewstate and manage it
    yourself. What I ended up doing is saving the DataSet result in the view
    state too that way even though I am binding on every postback, the net
    result is still only one DB hit. Only one problem remains. The fields that
    are shown in edit mode do not hold their values when a post is made that
    shows a validation error. I need to somehow get the Forms values and
    populate my controls with them as in the old ASP days. Any suggestions?

    Thanks
    Perry


    "Alvin Bruney [MVP]" <vapor at steaming post office> wrote in message
    news:%23CMdPB3jEHA.3632@TK2MSFTNGP09.phx.gbl...
    > you will need to bind on every request, or you can try putting the bind
    > code early in the pipeline so that it can participate in viewstate. you
    > will have to look at the pipeline events to find a suitable one (prerender
    > comes to mind but i'm not sure that it is early enough to participate in
    > viewstate)
    >
    > --
    > Regards,
    > Alvin Bruney
    > [ASP.NET MVP [url]http://mvp.support.microsoft.com/default.aspx][/url]
    > Got tidbits? Get it here... [url]http://tinyurl.com/27cok[/url]
    > "Perecli Manole" <Perry@argowin.com> wrote in message
    > news:OF7oY9ujEHA.592@TK2MSFTNGP11.phx.gbl...
    >> You missunderstand my requirement. The reason I need to add a row
    >> dynamicaly to the grid is because my row table strucuture needs to be
    >> changed. For every row in the database I need two rows in the grid. First
    >> row for each record should have one column structure and shows half the
    >> data while the second row has a different column structure and shows the
    >> other half of the data. In edit mode I need to go back to a "signle
    >> row/single column" because I show an entry form in it. I have achieved
    >> this by altering the grid's structure in the DataBind event however I
    >> have the problem described in my previous post.
    >>
    >> Perry
    >>
    >>
    >> "Alvin Bruney [MVP]" <vapor at steaming post office> wrote in message
    >> news:u2y3qpTjEHA.3876@TK2MSFTNGP15.phx.gbl...
    >>> what you need to do is add the rows to the dataset instead. whenever you
    >>> bind, the extra rows are always there and you don't need to go thru the
    >>> hocus pocus of postback and viewstate hell
    >>>
    >>> --
    >>> Regards,
    >>> Alvin Bruney
    >>> [ASP.NET MVP [url]http://mvp.support.microsoft.com/default.aspx][/url]
    >>> Got tidbits? Get it here... [url]http://tinyurl.com/27cok[/url]
    >>> "Perecli Manole" <Perry@argowin.com> wrote in message
    >>> news:Ooyo88%23iEHA.2140@TK2MSFTNGP15.phx.gbl...
    >>>> In my DataGrid I need to have two rows of data for every bound record.
    >>>> I have successfully achieved this by adding datagrid items and cells
    >>>> through code in the "DataGrid.ItemDataBound" event. The problem is that
    >>>> on post back my added rows do not stay. Aparently one needs to recreate
    >>>> them each page request. I have read several articles that suggest
    >>>> building up your grid layout in the "DataGrid.ItemCreated" event which
    >>>> gets called every request. So I put my row adding code there but then I
    >>>> realized that this event gets called before the framework adds its
    >>>> default row in the grid which creates a problem. I need my row to be
    >>>> added after the framework adds the default row so that it can be placed
    >>>> below it. I can not place a row with an index after a row that has not
    >>>> been created by the framework. So for now it seems like the only
    >>>> solution is to bind the grid on every request which is a waste. Is
    >>>> there another solution.
    >>>>
    >>>> Perry
    >>>>
    >>>
    >>>
    >>
    >>
    >
    >

    Perecli Manole Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139