Solved

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

Posted on 2012-03-10
3
162 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 250 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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

730 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