Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1059
Retrieve cell value
posted

Hi,

I use the following code to retrieve the cell value when the groupbybox is hidden( the GroupBy is fixed)

 

dValue =

Double.Parse(Gridview2.Rows[0].Cells["Column2"].Value.ToString());

 

 

My question is, if I turn on the groupbox and allow the user to change the GroupBy columns, how can i retrieve this value ?

Here's the sample of my grid

(- )Column 1 :

             Column2        Column3

              10000            15

              2000              16

How do I make sure I always get this value no matter how the column is grouped?

Thanks
Joe

 

Parents
No Data
Reply
  • 469350
    Offline posted

    Hi Joe,

    It depends on what value you want. Your code here is always referencing row 0.

    But, as I'm sure you probably noticed, once you group the rows, row 0 will become a GroupByRow that doesn't have any cells.

    So you need to walk down the chain and get to the real data row. But which one do you want?

    The first row in the first group?

    It's pretty unusual to need to target a specific row like that via the row index. Row 0 is unlikely to be anything special compared to other rows in the grid.

    If that's what you want, though - to get the first data row, then you would have to get row 0, check the IsGroupByRow property. If it is one, then you have to cast it to a GroupByRow and access it's Rows property to get it's child rows. The child row could also be a GroupByRow, though - since you can have multiple levels of grouping. So you have to keep repeating that process until you find a row that is not a GroupByRow.

Children