Datagrid Add new Row problkem

Discussion in 'ASP .Net Datagrid Control' started by Vishal, Feb 23, 2005.

  1. Vishal

    Vishal Guest

    Hello,

    I have a datagrid, which creates the columns
    dynamically based on the columns in the dataset. Now I
    need to add an additional row for each exisiting row AND
    hide that row, by default. This row will contain my
    usercontrol, which I will add also dynamically.
    Unfortunaly I am not able to do so. I tried two options:

    1.) I added the rows to the dataset and bound the dataset
    to the datagrid.

    - The problem however is, that I am not able to set the
    span of that row somehow. I set it, but it doesnt take it.

    - The second problem is that I am not able to hide it. I
    dont see any attributes property for the DataRow. Here is
    the code:

    ...begin loop through the rows
    Dim NestedGridRow As DataRow = ds.Tables(0).NewRow
    Dim NestedCell As New TableCell
    NestedCell.ColumnSpan = 3 'ds.Tables(0).Columns.Count
    ds.Tables(0).Rows.InsertAt(NestedGridRow, nRowPosition)
    nRowPosition = nRowPosition + 2
    ...end loop through the rows

    2.) I tried to add the columns direclty to the datagrid,
    via the following code:

    ...begin loop through the rows
    Dim dgItem As DataGridItem
    Dim dgCell As TableCell
    dgItem = New DataGridItem(0, 0, ListItemType.Item)
    dgCell = New TableCell
    dgCell.ColumnSpan = AADataGridStores.Columns.Count
    dgItem.Cells.Add(dgCell)
    dgCell.Text = "Testing something..."
    Dim t As Table = AADataGridStores.Controls(0)
    t.Rows.AddAt(nRowPosition, dgItem)
    nRowPosition = nRowPosition + 2
    ...end loop through the rows

    But this doesnt work too and it gives the error:
    Specified argument was out of the range of valid values.
    Parameter name: index

    Now how I am supposed to add a new row which I can hide?
    Manually, I would place the row into a placeholder and set
    the placeholder property either to true/false. But I am
    not getting how to do that in my situation. Can somebody
    please help me with this one?

    Thanks
     
    Vishal, Feb 23, 2005
    #1
    1. Advertising

  2. Vishal

    Elton Wang Guest

    Hi Vishal,

    I think basically your code of second option is OK. But,
    there two things you should take into consideration:

    1. Where to run the code? It should be after datagrid data
    binding. It may be in PreRender.

    2. Loop scope. Depending on different setting, you may
    have or not Pager, Header, Footer. If you have any of
    them, you should count them and add rows beyond them.

    HTH

    Elton Wang





    >-----Original Message-----
    >Hello,
    >
    > I have a datagrid, which creates the columns
    >dynamically based on the columns in the dataset. Now I
    >need to add an additional row for each exisiting row AND
    >hide that row, by default. This row will contain my
    >usercontrol, which I will add also dynamically.
    >Unfortunaly I am not able to do so. I tried two options:
    >
    >1.) I added the rows to the dataset and bound the dataset
    >to the datagrid.
    >
    >- The problem however is, that I am not able to set the
    >span of that row somehow. I set it, but it doesnt take

    it.
    >
    >- The second problem is that I am not able to hide it. I
    >dont see any attributes property for the DataRow. Here is
    >the code:
    >
    >...begin loop through the rows
    > Dim NestedGridRow As DataRow = ds.Tables(0).NewRow
    > Dim NestedCell As New TableCell
    > NestedCell.ColumnSpan = 3 'ds.Tables(0).Columns.Count
    > ds.Tables(0).Rows.InsertAt(NestedGridRow, nRowPosition)
    > nRowPosition = nRowPosition + 2
    >...end loop through the rows
    >
    >2.) I tried to add the columns direclty to the datagrid,
    >via the following code:
    >
    >...begin loop through the rows
    > Dim dgItem As DataGridItem
    > Dim dgCell As TableCell
    > dgItem = New DataGridItem(0, 0, ListItemType.Item)
    > dgCell = New TableCell
    > dgCell.ColumnSpan = AADataGridStores.Columns.Count
    > dgItem.Cells.Add(dgCell)
    > dgCell.Text = "Testing something..."
    > Dim t As Table = AADataGridStores.Controls(0)
    > t.Rows.AddAt(nRowPosition, dgItem)
    > nRowPosition = nRowPosition + 2
    >...end loop through the rows
    >
    >But this doesnt work too and it gives the error:
    >Specified argument was out of the range of valid values.
    >Parameter name: index
    >
    >Now how I am supposed to add a new row which I can hide?
    >Manually, I would place the row into a placeholder and

    set
    >the placeholder property either to true/false. But I am
    >not getting how to do that in my situation. Can somebody
    >please help me with this one?
    >
    >Thanks
    >
    >.
    >
     
    Elton Wang, Feb 23, 2005
    #2
    1. Advertising

  3. Vishal

    Vishal Guest

    Hi Elton,

    But i got the error as provided in the first message. I
    am adding the code right now in Init. Do you think thats
    the problem? How should I hide the row? Basically, the
    datagrid will contain a button in each row, which will
    lets me hide or show the nested row. As said I would did
    that with a placeholder, but dunno, how to do it in my
    current situation. Any help is greatly appreciated.

    Thanks


    >-----Original Message-----
    >Hi Vishal,
    >
    >I think basically your code of second option is OK. But,
    >there two things you should take into consideration:
    >
    >1. Where to run the code? It should be after datagrid

    data
    >binding. It may be in PreRender.
    >
    >2. Loop scope. Depending on different setting, you may
    >have or not Pager, Header, Footer. If you have any of
    >them, you should count them and add rows beyond them.
    >
    >HTH
    >
    >Elton Wang
    >
    >
    >
    >
    >
    >>-----Original Message-----
    >>Hello,
    >>
    >> I have a datagrid, which creates the columns
    >>dynamically based on the columns in the dataset. Now I
    >>need to add an additional row for each exisiting row AND
    >>hide that row, by default. This row will contain my
    >>usercontrol, which I will add also dynamically.
    >>Unfortunaly I am not able to do so. I tried two options:
    >>
    >>1.) I added the rows to the dataset and bound the

    dataset
    >>to the datagrid.
    >>
    >>- The problem however is, that I am not able to set the
    >>span of that row somehow. I set it, but it doesnt take

    >it.
    >>
    >>- The second problem is that I am not able to hide it. I
    >>dont see any attributes property for the DataRow. Here

    is
    >>the code:
    >>
    >>...begin loop through the rows
    >> Dim NestedGridRow As DataRow = ds.Tables(0).NewRow
    >> Dim NestedCell As New TableCell
    >> NestedCell.ColumnSpan = 3 'ds.Tables(0).Columns.Count
    >> ds.Tables(0).Rows.InsertAt(NestedGridRow, nRowPosition)
    >> nRowPosition = nRowPosition + 2
    >>...end loop through the rows
    >>
    >>2.) I tried to add the columns direclty to the datagrid,
    >>via the following code:
    >>
    >>...begin loop through the rows
    >> Dim dgItem As DataGridItem
    >> Dim dgCell As TableCell
    >> dgItem = New DataGridItem(0, 0, ListItemType.Item)
    >> dgCell = New TableCell
    >> dgCell.ColumnSpan = AADataGridStores.Columns.Count
    >> dgItem.Cells.Add(dgCell)
    >> dgCell.Text = "Testing something..."
    >> Dim t As Table = AADataGridStores.Controls(0)
    >> t.Rows.AddAt(nRowPosition, dgItem)
    >> nRowPosition = nRowPosition + 2
    >>...end loop through the rows
    >>
    >>But this doesnt work too and it gives the error:
    >>Specified argument was out of the range of valid values.
    >>Parameter name: index
    >>
    >>Now how I am supposed to add a new row which I can hide?
    >>Manually, I would place the row into a placeholder and

    >set
    >>the placeholder property either to true/false. But I am
    >>not getting how to do that in my situation. Can somebody
    >>please help me with this one?
    >>
    >>Thanks
    >>
    >>.
    >>

    >.
    >
     
    Vishal, Feb 23, 2005
    #3
  4. Vishal

    Elton Wang Guest

    Hi Vishal,

    As I mentioned, your logic is OK. But there are maybe two
    things (maybe one of them maybe both of them) that cause
    the trouble. One maybe is in wrong place to run your logic
    (you can move code to Datagrid_PreRender). Another one is
    from and to which exact row position you add those new
    rows, I mean in

    NRowPosition = ?startPositin
    While (condition ?)

    Currently you are using
    dgCell.Text = "Testing something..."

    You might use
    dgCell.Controls.Add(yourcontrol)
    in real situation.

    HTH

    Elton

    >-----Original Message-----
    >Hi Elton,
    >
    > But i got the error as provided in the first message.

    I
    >am adding the code right now in Init. Do you think thats
    >the problem? How should I hide the row? Basically, the
    >datagrid will contain a button in each row, which will
    >lets me hide or show the nested row. As said I would did
    >that with a placeholder, but dunno, how to do it in my
    >current situation. Any help is greatly appreciated.
    >
    >Thanks
    >
    >
    >>-----Original Message-----
    >>Hi Vishal,
    >>
    >>I think basically your code of second option is OK. But,
    >>there two things you should take into consideration:
    >>
    >>1. Where to run the code? It should be after datagrid

    >data
    >>binding. It may be in PreRender.
    >>
    >>2. Loop scope. Depending on different setting, you may
    >>have or not Pager, Header, Footer. If you have any of
    >>them, you should count them and add rows beyond them.
    >>
    >>HTH
    >>
    >>Elton Wang
    >>
    >>
    >>
    >>
    >>
    >>>-----Original Message-----
    >>>Hello,
    >>>
    >>> I have a datagrid, which creates the columns
    >>>dynamically based on the columns in the dataset. Now I
    >>>need to add an additional row for each exisiting row

    AND
    >>>hide that row, by default. This row will contain my
    >>>usercontrol, which I will add also dynamically.
    >>>Unfortunaly I am not able to do so. I tried two options:
    >>>
    >>>1.) I added the rows to the dataset and bound the

    >dataset
    >>>to the datagrid.
    >>>
    >>>- The problem however is, that I am not able to set the
    >>>span of that row somehow. I set it, but it doesnt take

    >>it.
    >>>
    >>>- The second problem is that I am not able to hide it.

    I
    >>>dont see any attributes property for the DataRow. Here

    >is
    >>>the code:
    >>>
    >>>...begin loop through the rows
    >>> Dim NestedGridRow As DataRow = ds.Tables(0).NewRow
    >>> Dim NestedCell As New TableCell
    >>> NestedCell.ColumnSpan = 3 'ds.Tables(0).Columns.Count
    >>> ds.Tables(0).Rows.InsertAt(NestedGridRow,

    nRowPosition)
    >>> nRowPosition = nRowPosition + 2
    >>>...end loop through the rows
    >>>
    >>>2.) I tried to add the columns direclty to the

    datagrid,
    >>>via the following code:
    >>>
    >>>...begin loop through the rows
    >>> Dim dgItem As DataGridItem
    >>> Dim dgCell As TableCell
    >>> dgItem = New DataGridItem(0, 0, ListItemType.Item)
    >>> dgCell = New TableCell
    >>> dgCell.ColumnSpan = AADataGridStores.Columns.Count
    >>> dgItem.Cells.Add(dgCell)
    >>> dgCell.Text = "Testing something..."
    >>> Dim t As Table = AADataGridStores.Controls(0)
    >>> t.Rows.AddAt(nRowPosition, dgItem)
    >>> nRowPosition = nRowPosition + 2
    >>>...end loop through the rows
    >>>
    >>>But this doesnt work too and it gives the error:
    >>>Specified argument was out of the range of valid

    values.
    >>>Parameter name: index
    >>>
    >>>Now how I am supposed to add a new row which I can

    hide?
    >>>Manually, I would place the row into a placeholder and

    >>set
    >>>the placeholder property either to true/false. But I am
    >>>not getting how to do that in my situation. Can

    somebody
    >>>please help me with this one?
    >>>
    >>>Thanks
    >>>
    >>>.
    >>>

    >>.
    >>

    >.
    >
     
    Elton Wang, Feb 23, 2005
    #4
  5. Vishal

    Vishal Guest

    Hey Elton,

    thanks for responding. I will try to move the code but
    what about hiding the row? How should I do that?


    >-----Original Message-----
    >Hi Vishal,
    >
    >As I mentioned, your logic is OK. But there are maybe

    two
    >things (maybe one of them maybe both of them) that cause
    >the trouble. One maybe is in wrong place to run your

    logic
    >(you can move code to Datagrid_PreRender). Another one is
    >from and to which exact row position you add those new
    >rows, I mean in
    >
    >NRowPosition = ?startPositin
    >While (condition ?)
    >
    >Currently you are using
    >dgCell.Text = "Testing something..."
    >
    >You might use
    >dgCell.Controls.Add(yourcontrol)
    >in real situation.
    >
    >HTH
    >
    >Elton
    >
    >>-----Original Message-----
    >>Hi Elton,
    >>
    >> But i got the error as provided in the first message.

    >I
    >>am adding the code right now in Init. Do you think thats
    >>the problem? How should I hide the row? Basically, the
    >>datagrid will contain a button in each row, which will
    >>lets me hide or show the nested row. As said I would did
    >>that with a placeholder, but dunno, how to do it in my
    >>current situation. Any help is greatly appreciated.
    >>
    >>Thanks
    >>
    >>
    >>>-----Original Message-----
    >>>Hi Vishal,
    >>>
    >>>I think basically your code of second option is OK.

    But,
    >>>there two things you should take into consideration:
    >>>
    >>>1. Where to run the code? It should be after datagrid

    >>data
    >>>binding. It may be in PreRender.
    >>>
    >>>2. Loop scope. Depending on different setting, you may
    >>>have or not Pager, Header, Footer. If you have any of
    >>>them, you should count them and add rows beyond them.
    >>>
    >>>HTH
    >>>
    >>>Elton Wang
    >>>
    >>>
    >>>
    >>>
    >>>
    >>>>-----Original Message-----
    >>>>Hello,
    >>>>
    >>>> I have a datagrid, which creates the columns
    >>>>dynamically based on the columns in the dataset. Now I
    >>>>need to add an additional row for each exisiting row

    >AND
    >>>>hide that row, by default. This row will contain my
    >>>>usercontrol, which I will add also dynamically.
    >>>>Unfortunaly I am not able to do so. I tried two

    options:
    >>>>
    >>>>1.) I added the rows to the dataset and bound the

    >>dataset
    >>>>to the datagrid.
    >>>>
    >>>>- The problem however is, that I am not able to set

    the
    >>>>span of that row somehow. I set it, but it doesnt take
    >>>it.
    >>>>
    >>>>- The second problem is that I am not able to hide it.

    >I
    >>>>dont see any attributes property for the DataRow. Here

    >>is
    >>>>the code:
    >>>>
    >>>>...begin loop through the rows
    >>>> Dim NestedGridRow As DataRow = ds.Tables(0).NewRow
    >>>> Dim NestedCell As New TableCell
    >>>> NestedCell.ColumnSpan = 3 'ds.Tables(0).Columns.Count
    >>>> ds.Tables(0).Rows.InsertAt(NestedGridRow,

    >nRowPosition)
    >>>> nRowPosition = nRowPosition + 2
    >>>>...end loop through the rows
    >>>>
    >>>>2.) I tried to add the columns direclty to the

    >datagrid,
    >>>>via the following code:
    >>>>
    >>>>...begin loop through the rows
    >>>> Dim dgItem As DataGridItem
    >>>> Dim dgCell As TableCell
    >>>> dgItem = New DataGridItem(0, 0, ListItemType.Item)
    >>>> dgCell = New TableCell
    >>>> dgCell.ColumnSpan = AADataGridStores.Columns.Count
    >>>> dgItem.Cells.Add(dgCell)
    >>>> dgCell.Text = "Testing something..."
    >>>> Dim t As Table = AADataGridStores.Controls(0)
    >>>> t.Rows.AddAt(nRowPosition, dgItem)
    >>>> nRowPosition = nRowPosition + 2
    >>>>...end loop through the rows
    >>>>
    >>>>But this doesnt work too and it gives the error:
    >>>>Specified argument was out of the range of valid

    >values.
    >>>>Parameter name: index
    >>>>
    >>>>Now how I am supposed to add a new row which I can

    >hide?
    >>>>Manually, I would place the row into a placeholder and
    >>>set
    >>>>the placeholder property either to true/false. But I

    am
    >>>>not getting how to do that in my situation. Can

    >somebody
    >>>>please help me with this one?
    >>>>
    >>>>Thanks
    >>>>
    >>>>.
    >>>>
    >>>.
    >>>

    >>.
    >>

    >.
    >
     
    Vishal, Feb 23, 2005
    #5
  6. Vishal

    Vishal Guest

    Is OnPreRender and DataGrid_PreRender the same? I have
    currently defined it in page like this:

    Protected Overloads Sub OnPreRender()
    ....
    end sub

    Is that ok?


    >-----Original Message-----
    >Hi Vishal,
    >
    >As I mentioned, your logic is OK. But there are maybe

    two
    >things (maybe one of them maybe both of them) that cause
    >the trouble. One maybe is in wrong place to run your

    logic
    >(you can move code to Datagrid_PreRender). Another one is
    >from and to which exact row position you add those new
    >rows, I mean in
    >
    >NRowPosition = ?startPositin
    >While (condition ?)
    >
    >Currently you are using
    >dgCell.Text = "Testing something..."
    >
    >You might use
    >dgCell.Controls.Add(yourcontrol)
    >in real situation.
    >
    >HTH
    >
    >Elton
    >
    >>-----Original Message-----
    >>Hi Elton,
    >>
    >> But i got the error as provided in the first message.

    >I
    >>am adding the code right now in Init. Do you think thats
    >>the problem? How should I hide the row? Basically, the
    >>datagrid will contain a button in each row, which will
    >>lets me hide or show the nested row. As said I would did
    >>that with a placeholder, but dunno, how to do it in my
    >>current situation. Any help is greatly appreciated.
    >>
    >>Thanks
    >>
    >>
    >>>-----Original Message-----
    >>>Hi Vishal,
    >>>
    >>>I think basically your code of second option is OK.

    But,
    >>>there two things you should take into consideration:
    >>>
    >>>1. Where to run the code? It should be after datagrid

    >>data
    >>>binding. It may be in PreRender.
    >>>
    >>>2. Loop scope. Depending on different setting, you may
    >>>have or not Pager, Header, Footer. If you have any of
    >>>them, you should count them and add rows beyond them.
    >>>
    >>>HTH
    >>>
    >>>Elton Wang
    >>>
    >>>
    >>>
    >>>
    >>>
    >>>>-----Original Message-----
    >>>>Hello,
    >>>>
    >>>> I have a datagrid, which creates the columns
    >>>>dynamically based on the columns in the dataset. Now I
    >>>>need to add an additional row for each exisiting row

    >AND
    >>>>hide that row, by default. This row will contain my
    >>>>usercontrol, which I will add also dynamically.
    >>>>Unfortunaly I am not able to do so. I tried two

    options:
    >>>>
    >>>>1.) I added the rows to the dataset and bound the

    >>dataset
    >>>>to the datagrid.
    >>>>
    >>>>- The problem however is, that I am not able to set

    the
    >>>>span of that row somehow. I set it, but it doesnt take
    >>>it.
    >>>>
    >>>>- The second problem is that I am not able to hide it.

    >I
    >>>>dont see any attributes property for the DataRow. Here

    >>is
    >>>>the code:
    >>>>
    >>>>...begin loop through the rows
    >>>> Dim NestedGridRow As DataRow = ds.Tables(0).NewRow
    >>>> Dim NestedCell As New TableCell
    >>>> NestedCell.ColumnSpan = 3 'ds.Tables(0).Columns.Count
    >>>> ds.Tables(0).Rows.InsertAt(NestedGridRow,

    >nRowPosition)
    >>>> nRowPosition = nRowPosition + 2
    >>>>...end loop through the rows
    >>>>
    >>>>2.) I tried to add the columns direclty to the

    >datagrid,
    >>>>via the following code:
    >>>>
    >>>>...begin loop through the rows
    >>>> Dim dgItem As DataGridItem
    >>>> Dim dgCell As TableCell
    >>>> dgItem = New DataGridItem(0, 0, ListItemType.Item)
    >>>> dgCell = New TableCell
    >>>> dgCell.ColumnSpan = AADataGridStores.Columns.Count
    >>>> dgItem.Cells.Add(dgCell)
    >>>> dgCell.Text = "Testing something..."
    >>>> Dim t As Table = AADataGridStores.Controls(0)
    >>>> t.Rows.AddAt(nRowPosition, dgItem)
    >>>> nRowPosition = nRowPosition + 2
    >>>>...end loop through the rows
    >>>>
    >>>>But this doesnt work too and it gives the error:
    >>>>Specified argument was out of the range of valid

    >values.
    >>>>Parameter name: index
    >>>>
    >>>>Now how I am supposed to add a new row which I can

    >hide?
    >>>>Manually, I would place the row into a placeholder and
    >>>set
    >>>>the placeholder property either to true/false. But I

    am
    >>>>not getting how to do that in my situation. Can

    >somebody
    >>>>please help me with this one?
    >>>>
    >>>>Thanks
    >>>>
    >>>>.
    >>>>
    >>>.
    >>>

    >>.
    >>

    >.
    >
     
    Vishal, Feb 23, 2005
    #6
  7. Vishal

    Vishal Guest

    Furtheremore isnt PreRender already to late? I mean will
    it keep its viewstate?


    >-----Original Message-----
    >Hi Vishal,
    >
    >As I mentioned, your logic is OK. But there are maybe

    two
    >things (maybe one of them maybe both of them) that cause
    >the trouble. One maybe is in wrong place to run your

    logic
    >(you can move code to Datagrid_PreRender). Another one is
    >from and to which exact row position you add those new
    >rows, I mean in
    >
    >NRowPosition = ?startPositin
    >While (condition ?)
    >
    >Currently you are using
    >dgCell.Text = "Testing something..."
    >
    >You might use
    >dgCell.Controls.Add(yourcontrol)
    >in real situation.
    >
    >HTH
    >
    >Elton
    >
    >>-----Original Message-----
    >>Hi Elton,
    >>
    >> But i got the error as provided in the first message.

    >I
    >>am adding the code right now in Init. Do you think thats
    >>the problem? How should I hide the row? Basically, the
    >>datagrid will contain a button in each row, which will
    >>lets me hide or show the nested row. As said I would did
    >>that with a placeholder, but dunno, how to do it in my
    >>current situation. Any help is greatly appreciated.
    >>
    >>Thanks
    >>
    >>
    >>>-----Original Message-----
    >>>Hi Vishal,
    >>>
    >>>I think basically your code of second option is OK.

    But,
    >>>there two things you should take into consideration:
    >>>
    >>>1. Where to run the code? It should be after datagrid

    >>data
    >>>binding. It may be in PreRender.
    >>>
    >>>2. Loop scope. Depending on different setting, you may
    >>>have or not Pager, Header, Footer. If you have any of
    >>>them, you should count them and add rows beyond them.
    >>>
    >>>HTH
    >>>
    >>>Elton Wang
    >>>
    >>>
    >>>
    >>>
    >>>
    >>>>-----Original Message-----
    >>>>Hello,
    >>>>
    >>>> I have a datagrid, which creates the columns
    >>>>dynamically based on the columns in the dataset. Now I
    >>>>need to add an additional row for each exisiting row

    >AND
    >>>>hide that row, by default. This row will contain my
    >>>>usercontrol, which I will add also dynamically.
    >>>>Unfortunaly I am not able to do so. I tried two

    options:
    >>>>
    >>>>1.) I added the rows to the dataset and bound the

    >>dataset
    >>>>to the datagrid.
    >>>>
    >>>>- The problem however is, that I am not able to set

    the
    >>>>span of that row somehow. I set it, but it doesnt take
    >>>it.
    >>>>
    >>>>- The second problem is that I am not able to hide it.

    >I
    >>>>dont see any attributes property for the DataRow. Here

    >>is
    >>>>the code:
    >>>>
    >>>>...begin loop through the rows
    >>>> Dim NestedGridRow As DataRow = ds.Tables(0).NewRow
    >>>> Dim NestedCell As New TableCell
    >>>> NestedCell.ColumnSpan = 3 'ds.Tables(0).Columns.Count
    >>>> ds.Tables(0).Rows.InsertAt(NestedGridRow,

    >nRowPosition)
    >>>> nRowPosition = nRowPosition + 2
    >>>>...end loop through the rows
    >>>>
    >>>>2.) I tried to add the columns direclty to the

    >datagrid,
    >>>>via the following code:
    >>>>
    >>>>...begin loop through the rows
    >>>> Dim dgItem As DataGridItem
    >>>> Dim dgCell As TableCell
    >>>> dgItem = New DataGridItem(0, 0, ListItemType.Item)
    >>>> dgCell = New TableCell
    >>>> dgCell.ColumnSpan = AADataGridStores.Columns.Count
    >>>> dgItem.Cells.Add(dgCell)
    >>>> dgCell.Text = "Testing something..."
    >>>> Dim t As Table = AADataGridStores.Controls(0)
    >>>> t.Rows.AddAt(nRowPosition, dgItem)
    >>>> nRowPosition = nRowPosition + 2
    >>>>...end loop through the rows
    >>>>
    >>>>But this doesnt work too and it gives the error:
    >>>>Specified argument was out of the range of valid

    >values.
    >>>>Parameter name: index
    >>>>
    >>>>Now how I am supposed to add a new row which I can

    >hide?
    >>>>Manually, I would place the row into a placeholder and
    >>>set
    >>>>the placeholder property either to true/false. But I

    am
    >>>>not getting how to do that in my situation. Can

    >somebody
    >>>>please help me with this one?
    >>>>
    >>>>Thanks
    >>>>
    >>>>.
    >>>>
    >>>.
    >>>

    >>.
    >>

    >.
    >
     
    Vishal, Feb 23, 2005
    #7
  8. Vishal

    Vishal Guest

    I added the code to the PreRender and now my complete dg
    doesnt show up...

    Private Sub AADataGridStores_PreRender(ByVal sender As
    Object, ByVal e As System.EventArgs) Handles
    AADataGridStores.PreRender
    CreateColumns()
    End Sub


    >-----Original Message-----
    >Hi Vishal,
    >
    >As I mentioned, your logic is OK. But there are maybe

    two
    >things (maybe one of them maybe both of them) that cause
    >the trouble. One maybe is in wrong place to run your

    logic
    >(you can move code to Datagrid_PreRender). Another one is
    >from and to which exact row position you add those new
    >rows, I mean in
    >
    >NRowPosition = ?startPositin
    >While (condition ?)
    >
    >Currently you are using
    >dgCell.Text = "Testing something..."
    >
    >You might use
    >dgCell.Controls.Add(yourcontrol)
    >in real situation.
    >
    >HTH
    >
    >Elton
    >
    >>-----Original Message-----
    >>Hi Elton,
    >>
    >> But i got the error as provided in the first message.

    >I
    >>am adding the code right now in Init. Do you think thats
    >>the problem? How should I hide the row? Basically, the
    >>datagrid will contain a button in each row, which will
    >>lets me hide or show the nested row. As said I would did
    >>that with a placeholder, but dunno, how to do it in my
    >>current situation. Any help is greatly appreciated.
    >>
    >>Thanks
    >>
    >>
    >>>-----Original Message-----
    >>>Hi Vishal,
    >>>
    >>>I think basically your code of second option is OK.

    But,
    >>>there two things you should take into consideration:
    >>>
    >>>1. Where to run the code? It should be after datagrid

    >>data
    >>>binding. It may be in PreRender.
    >>>
    >>>2. Loop scope. Depending on different setting, you may
    >>>have or not Pager, Header, Footer. If you have any of
    >>>them, you should count them and add rows beyond them.
    >>>
    >>>HTH
    >>>
    >>>Elton Wang
    >>>
    >>>
    >>>
    >>>
    >>>
    >>>>-----Original Message-----
    >>>>Hello,
    >>>>
    >>>> I have a datagrid, which creates the columns
    >>>>dynamically based on the columns in the dataset. Now I
    >>>>need to add an additional row for each exisiting row

    >AND
    >>>>hide that row, by default. This row will contain my
    >>>>usercontrol, which I will add also dynamically.
    >>>>Unfortunaly I am not able to do so. I tried two

    options:
    >>>>
    >>>>1.) I added the rows to the dataset and bound the

    >>dataset
    >>>>to the datagrid.
    >>>>
    >>>>- The problem however is, that I am not able to set

    the
    >>>>span of that row somehow. I set it, but it doesnt take
    >>>it.
    >>>>
    >>>>- The second problem is that I am not able to hide it.

    >I
    >>>>dont see any attributes property for the DataRow. Here

    >>is
    >>>>the code:
    >>>>
    >>>>...begin loop through the rows
    >>>> Dim NestedGridRow As DataRow = ds.Tables(0).NewRow
    >>>> Dim NestedCell As New TableCell
    >>>> NestedCell.ColumnSpan = 3 'ds.Tables(0).Columns.Count
    >>>> ds.Tables(0).Rows.InsertAt(NestedGridRow,

    >nRowPosition)
    >>>> nRowPosition = nRowPosition + 2
    >>>>...end loop through the rows
    >>>>
    >>>>2.) I tried to add the columns direclty to the

    >datagrid,
    >>>>via the following code:
    >>>>
    >>>>...begin loop through the rows
    >>>> Dim dgItem As DataGridItem
    >>>> Dim dgCell As TableCell
    >>>> dgItem = New DataGridItem(0, 0, ListItemType.Item)
    >>>> dgCell = New TableCell
    >>>> dgCell.ColumnSpan = AADataGridStores.Columns.Count
    >>>> dgItem.Cells.Add(dgCell)
    >>>> dgCell.Text = "Testing something..."
    >>>> Dim t As Table = AADataGridStores.Controls(0)
    >>>> t.Rows.AddAt(nRowPosition, dgItem)
    >>>> nRowPosition = nRowPosition + 2
    >>>>...end loop through the rows
    >>>>
    >>>>But this doesnt work too and it gives the error:
    >>>>Specified argument was out of the range of valid

    >values.
    >>>>Parameter name: index
    >>>>
    >>>>Now how I am supposed to add a new row which I can

    >hide?
    >>>>Manually, I would place the row into a placeholder and
    >>>set
    >>>>the placeholder property either to true/false. But I

    am
    >>>>not getting how to do that in my situation. Can

    >somebody
    >>>>please help me with this one?
    >>>>
    >>>>Thanks
    >>>>
    >>>>.
    >>>>
    >>>.
    >>>

    >>.
    >>

    >.
    >
     
    Vishal, Feb 23, 2005
    #8
  9. Vishal

    Elton Wang Guest

    You are right. It seems the viewstate can't keep added
    rows, even add them very early (Page_Load, right after
    data binding). So once postback, it shows trouble. But it
    can't be done befor data binding. Currently I don't know
    how to figure it out. If you find solution, please share
    your idea.

    Elton

    >-----Original Message-----
    >Furtheremore isnt PreRender already to late? I mean will
    >it keep its viewstate?
    >
    >
    >>-----Original Message-----
    >>Hi Vishal,
    >>
    >>As I mentioned, your logic is OK. But there are maybe

    >two
    >>things (maybe one of them maybe both of them) that cause
    >>the trouble. One maybe is in wrong place to run your

    >logic
    >>(you can move code to Datagrid_PreRender). Another one

    is
    >>from and to which exact row position you add those new
    >>rows, I mean in
    >>
    >>NRowPosition = ?startPositin
    >>While (condition ?)
    >>
    >>Currently you are using
    >>dgCell.Text = "Testing something..."
    >>
    >>You might use
    >>dgCell.Controls.Add(yourcontrol)
    >>in real situation.
    >>
    >>HTH
    >>
    >>Elton
    >>
    >>>-----Original Message-----
    >>>Hi Elton,
    >>>
    >>> But i got the error as provided in the first

    message.
    >>I
    >>>am adding the code right now in Init. Do you think

    thats
    >>>the problem? How should I hide the row? Basically, the
    >>>datagrid will contain a button in each row, which will
    >>>lets me hide or show the nested row. As said I would

    did
    >>>that with a placeholder, but dunno, how to do it in my
    >>>current situation. Any help is greatly appreciated.
    >>>
    >>>Thanks
    >>>
    >>>
    >>>>-----Original Message-----
    >>>>Hi Vishal,
    >>>>
    >>>>I think basically your code of second option is OK.

    >But,
    >>>>there two things you should take into consideration:
    >>>>
    >>>>1. Where to run the code? It should be after datagrid
    >>>data
    >>>>binding. It may be in PreRender.
    >>>>
    >>>>2. Loop scope. Depending on different setting, you may
    >>>>have or not Pager, Header, Footer. If you have any of
    >>>>them, you should count them and add rows beyond them.
    >>>>
    >>>>HTH
    >>>>
    >>>>Elton Wang
    >>>>
    >>>>
    >>>>
    >>>>
    >>>>
    >>>>>-----Original Message-----
    >>>>>Hello,
    >>>>>
    >>>>> I have a datagrid, which creates the columns
    >>>>>dynamically based on the columns in the dataset. Now

    I
    >>>>>need to add an additional row for each exisiting row

    >>AND
    >>>>>hide that row, by default. This row will contain my
    >>>>>usercontrol, which I will add also dynamically.
    >>>>>Unfortunaly I am not able to do so. I tried two

    >options:
    >>>>>
    >>>>>1.) I added the rows to the dataset and bound the
    >>>dataset
    >>>>>to the datagrid.
    >>>>>
    >>>>>- The problem however is, that I am not able to set

    >the
    >>>>>span of that row somehow. I set it, but it doesnt

    take
    >>>>it.
    >>>>>
    >>>>>- The second problem is that I am not able to hide

    it.
    >>I
    >>>>>dont see any attributes property for the DataRow.

    Here
    >>>is
    >>>>>the code:
    >>>>>
    >>>>>...begin loop through the rows
    >>>>> Dim NestedGridRow As DataRow = ds.Tables(0).NewRow
    >>>>> Dim NestedCell As New TableCell
    >>>>> NestedCell.ColumnSpan = 3 'ds.Tables

    (0).Columns.Count
    >>>>> ds.Tables(0).Rows.InsertAt(NestedGridRow,

    >>nRowPosition)
    >>>>> nRowPosition = nRowPosition + 2
    >>>>>...end loop through the rows
    >>>>>
    >>>>>2.) I tried to add the columns direclty to the

    >>datagrid,
    >>>>>via the following code:
    >>>>>
    >>>>>...begin loop through the rows
    >>>>> Dim dgItem As DataGridItem
    >>>>> Dim dgCell As TableCell
    >>>>> dgItem = New DataGridItem(0, 0, ListItemType.Item)
    >>>>> dgCell = New TableCell
    >>>>> dgCell.ColumnSpan = AADataGridStores.Columns.Count
    >>>>> dgItem.Cells.Add(dgCell)
    >>>>> dgCell.Text = "Testing something..."
    >>>>> Dim t As Table = AADataGridStores.Controls(0)
    >>>>> t.Rows.AddAt(nRowPosition, dgItem)
    >>>>> nRowPosition = nRowPosition + 2
    >>>>>...end loop through the rows
    >>>>>
    >>>>>But this doesnt work too and it gives the error:
    >>>>>Specified argument was out of the range of valid

    >>values.
    >>>>>Parameter name: index
    >>>>>
    >>>>>Now how I am supposed to add a new row which I can

    >>hide?
    >>>>>Manually, I would place the row into a placeholder

    and
    >>>>set
    >>>>>the placeholder property either to true/false. But I

    >am
    >>>>>not getting how to do that in my situation. Can

    >>somebody
    >>>>>please help me with this one?
    >>>>>
    >>>>>Thanks
    >>>>>
    >>>>>.
    >>>>>
    >>>>.
    >>>>
    >>>.
    >>>

    >>.
    >>

    >.
    >
     
    Elton Wang, Feb 24, 2005
    #9
  10. Vishal

    Vishal Guest

    I am discussing this problem with somebody at the GDN
    forums:

    http://www.gotdotnet.com/Community/MessageBoard/Thread.aspx
    ?id=302261


    >-----Original Message-----
    >You are right. It seems the viewstate can't keep added
    >rows, even add them very early (Page_Load, right after
    >data binding). So once postback, it shows trouble. But it
    >can't be done befor data binding. Currently I don't know
    >how to figure it out. If you find solution, please share
    >your idea.
    >
    >Elton
    >
    >>-----Original Message-----
    >>Furtheremore isnt PreRender already to late? I mean will
    >>it keep its viewstate?
    >>
    >>
    >>>-----Original Message-----
    >>>Hi Vishal,
    >>>
    >>>As I mentioned, your logic is OK. But there are maybe

    >>two
    >>>things (maybe one of them maybe both of them) that

    cause
    >>>the trouble. One maybe is in wrong place to run your

    >>logic
    >>>(you can move code to Datagrid_PreRender). Another one

    >is
    >>>from and to which exact row position you add those new
    >>>rows, I mean in
    >>>
    >>>NRowPosition = ?startPositin
    >>>While (condition ?)
    >>>
    >>>Currently you are using
    >>>dgCell.Text = "Testing something..."
    >>>
    >>>You might use
    >>>dgCell.Controls.Add(yourcontrol)
    >>>in real situation.
    >>>
    >>>HTH
    >>>
    >>>Elton
    >>>
    >>>>-----Original Message-----
    >>>>Hi Elton,
    >>>>
    >>>> But i got the error as provided in the first

    >message.
    >>>I
    >>>>am adding the code right now in Init. Do you think

    >thats
    >>>>the problem? How should I hide the row? Basically, the
    >>>>datagrid will contain a button in each row, which will
    >>>>lets me hide or show the nested row. As said I would

    >did
    >>>>that with a placeholder, but dunno, how to do it in my
    >>>>current situation. Any help is greatly appreciated.
    >>>>
    >>>>Thanks
    >>>>
    >>>>
    >>>>>-----Original Message-----
    >>>>>Hi Vishal,
    >>>>>
    >>>>>I think basically your code of second option is OK.

    >>But,
    >>>>>there two things you should take into consideration:
    >>>>>
    >>>>>1. Where to run the code? It should be after datagrid
    >>>>data
    >>>>>binding. It may be in PreRender.
    >>>>>
    >>>>>2. Loop scope. Depending on different setting, you

    may
    >>>>>have or not Pager, Header, Footer. If you have any of
    >>>>>them, you should count them and add rows beyond them.
    >>>>>
    >>>>>HTH
    >>>>>
    >>>>>Elton Wang
    >>>>>
    >>>>>
    >>>>>
    >>>>>
    >>>>>
    >>>>>>-----Original Message-----
    >>>>>>Hello,
    >>>>>>
    >>>>>> I have a datagrid, which creates the columns
    >>>>>>dynamically based on the columns in the dataset. Now

    >I
    >>>>>>need to add an additional row for each exisiting row
    >>>AND
    >>>>>>hide that row, by default. This row will contain my
    >>>>>>usercontrol, which I will add also dynamically.
    >>>>>>Unfortunaly I am not able to do so. I tried two

    >>options:
    >>>>>>
    >>>>>>1.) I added the rows to the dataset and bound the
    >>>>dataset
    >>>>>>to the datagrid.
    >>>>>>
    >>>>>>- The problem however is, that I am not able to set

    >>the
    >>>>>>span of that row somehow. I set it, but it doesnt

    >take
    >>>>>it.
    >>>>>>
    >>>>>>- The second problem is that I am not able to hide

    >it.
    >>>I
    >>>>>>dont see any attributes property for the DataRow.

    >Here
    >>>>is
    >>>>>>the code:
    >>>>>>
    >>>>>>...begin loop through the rows
    >>>>>> Dim NestedGridRow As DataRow = ds.Tables(0).NewRow
    >>>>>> Dim NestedCell As New TableCell
    >>>>>> NestedCell.ColumnSpan = 3 'ds.Tables

    >(0).Columns.Count
    >>>>>> ds.Tables(0).Rows.InsertAt(NestedGridRow,
    >>>nRowPosition)
    >>>>>> nRowPosition = nRowPosition + 2
    >>>>>>...end loop through the rows
    >>>>>>
    >>>>>>2.) I tried to add the columns direclty to the
    >>>datagrid,
    >>>>>>via the following code:
    >>>>>>
    >>>>>>...begin loop through the rows
    >>>>>> Dim dgItem As DataGridItem
    >>>>>> Dim dgCell As TableCell
    >>>>>> dgItem = New DataGridItem(0, 0, ListItemType.Item)
    >>>>>> dgCell = New TableCell
    >>>>>> dgCell.ColumnSpan = AADataGridStores.Columns.Count
    >>>>>> dgItem.Cells.Add(dgCell)
    >>>>>> dgCell.Text = "Testing something..."
    >>>>>> Dim t As Table = AADataGridStores.Controls(0)
    >>>>>> t.Rows.AddAt(nRowPosition, dgItem)
    >>>>>> nRowPosition = nRowPosition + 2
    >>>>>>...end loop through the rows
    >>>>>>
    >>>>>>But this doesnt work too and it gives the error:
    >>>>>>Specified argument was out of the range of valid
    >>>values.
    >>>>>>Parameter name: index
    >>>>>>
    >>>>>>Now how I am supposed to add a new row which I can
    >>>hide?
    >>>>>>Manually, I would place the row into a placeholder

    >and
    >>>>>set
    >>>>>>the placeholder property either to true/false. But I

    >>am
    >>>>>>not getting how to do that in my situation. Can
    >>>somebody
    >>>>>>please help me with this one?
    >>>>>>
    >>>>>>Thanks
    >>>>>>
    >>>>>>.
    >>>>>>
    >>>>>.
    >>>>>
    >>>>.
    >>>>
    >>>.
    >>>

    >>.
    >>

    >.
    >
     
    Vishal, Feb 24, 2005
    #10
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?U3VyZXNo?=
    Replies:
    1
    Views:
    481
    Saravana
    Nov 22, 2004
  2. Replies:
    0
    Views:
    376
  3. Replies:
    0
    Views:
    437
  4. Paul
    Replies:
    1
    Views:
    2,380
    Hermit Dave
    Jul 11, 2008
  5. D
    Replies:
    0
    Views:
    239
Loading...

Share This Page