Solved

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

Posted on 2012-03-10
3
158 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
  • 2
3 Comments
 
LVL 9

Accepted Solution

by:
lojk earned 250 total points
Comment Utility
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
Comment Utility
Thank you so much - I've been tearing my hair out for weeks on this! :-)
0
 
LVL 9

Expert Comment

by:lojk
Comment Utility
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

763 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now