?
Solved

Code removing the wrong cells - how do I get the value of a cell in GridView

Posted on 2012-03-10
3
Medium Priority
?
165 Views
Last Modified: 2012-03-13
Hi I'm trying to add rowspan to the first cell in a group and then removing the subsequent cells but my code seems to be removing the wrong cells (e.g gvr.Cells.RemoveAt(0);).  How can I get the value of a cell in the following code so I can determine which cells are actually being removed??

foreach (GridViewRow gvr in gvWeeksCatches.Rows)
        {
            gvRowIndex = gvr.RowIndex;
            if (gvRowIndex == firstSpanRow)
            {
                gvr.Cells[0].RowSpan = numSpanRows;
                gvr.Cells[1].RowSpan = numSpanRows;
            }
            //if row is in rowspan group
            else if (gvRowIndex > firstSpanRow && gvRowIndex <= lastSpanRow)
            {
                gvr.Cells.RemoveAt(0);
                gvr.Cells.RemoveAt(1);
               
            }
            gvRowIndex++;

        }
0
Comment
Question by:Lorna70
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 9

Accepted Solution

by:
lojk earned 1000 total points
ID: 37706650
your code here

else if (gvRowIndex > firstSpanRow && gvRowIndex <= lastSpanRow)
            {
                gvr.Cells.RemoveAt(0);
                gvr.Cells.RemoveAt(1);
               
            }

is not doing what you think it is...

It is removing the first cell, then it is removing the *second* cell from that which remain (i.e. the first statement changes the list that you are operating upon).

to remove the first 2 cells you should do (my preference)

  {
                gvr.Cells.RemoveAt(0);
                gvr.Cells.RemoveAt(0);
               
            }

or even this would work better than what you have

  {
                gvr.Cells.RemoveAt(1);
                gvr.Cells.RemoveAt(0);
               
            }


if you think about it - it makes more sense..

Try laying out some playing cards on the table and replicating your code operations if you still dont understand what i mean.
0
 

Author Comment

by:Lorna70
ID: 37714080
Thank you so much - I've been tearing my hair out for weeks on this! :-)
0
 
LVL 9

Expert Comment

by:lojk
ID: 37714111
It was a bit of a glaring error but I've been down this road with similar issues so many times before - sometimes you just need a fresh pair of eyes on the subject.

Glad to have saved some of your hair, even if it's too late for mine. ;-)
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question