?
Solved

GridView RowEditing event & GridViewRow event

Posted on 2012-08-23
11
Medium Priority
?
1,055 Views
Last Modified: 2012-08-31
Hi I am trying to keep or display the row when the checkBox is checked, but under the
GridView1_RowEditing event, I am getting fa lse for the cb.Checked if checking.

Any idea how to work around it?

Thank you!!!

 protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
        {
            GridView1.EditIndex = e.NewEditIndex;  
          
                foreach (GridViewRow gr in GridView1.Rows)
                {
                    CheckBox cb = (CheckBox)gr.Cells[1].FindControl("CheckBox1");
                    if (cb.Checked == true)
                    {
                        gr.Visible = true;
                    }
                }             
            
       }

Open in new window

0
Comment
Question by:Rad1
11 Comments
 
LVL 23

Accepted Solution

by:
Christopher Kile earned 1336 total points
ID: 38327289
Well, one thing I noticed right away:

 if (cb.Checked == true)

is more correctly shown as

 if (cb.Checked)

I don't think that's your problem, but I'd still correct this ASAP.
0
 

Author Comment

by:Rad1
ID: 38327358
What I think needs to be done is:
1. Get the row number for the checkBox
2. assign true to the checkBox cb for that row.

I think this will make it work.

What is the syntax or how do I use the Griview functions to get it?
0
 
LVL 23

Assisted Solution

by:Christopher Kile
Christopher Kile earned 1336 total points
ID: 38327396
Dim row As GridViewRow = TaskGridView.Rows(e.NewEditIndex)

I do have a question, though: You're setting the Visible attribute of the entire row to True - If a row was not Visible, how do you plan to set the checkbox to make it visible in the RowEditing event?  If it was Visible, why are you setting it to Visible?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 23

Assisted Solution

by:Christopher Kile
Christopher Kile earned 1336 total points
ID: 38327400
Sorry, substitute your grid view's name for TaskGridView in the previous message.
0
 

Author Comment

by:Rad1
ID: 38327425
Sorry, code correction below:


protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
        {
            GridView1.EditIndex = e.NewEditIndex;  
          
                foreach (GridViewRow gr in GridView1.Rows)
                {
                    CheckBox cb = (CheckBox)gr.Cells[1].FindControl("CheckBox1");
                    if (cb.Checked == true)
                    {
                        gr.Visible = false;
                    }
                }             
            
       }

Open in new window

0
 

Author Comment

by:Rad1
ID: 38327431
Thank you!!!

I am using C# code and not VB (Dim row As GridViewRow = TaskGridView.Rows(e.NewEditIndex))

Would you please put it in code?
Do I just replace the e with e.NewEditIndex???
Don't I have to assign a new index?

Thank you!
0
 
LVL 20

Assisted Solution

by:informaniac
informaniac earned 332 total points
ID: 38327999
Can you show us the gridview markup. It's difficult to understand what you are trying to achieve.
0
 
LVL 19

Assisted Solution

by:Manoj Patil
Manoj Patil earned 332 total points
ID: 38328381
Are you going to Edit all rows that are checked ??

If Yes, this will help you

http://csharpdotnetfreak.blogspot.com/2009/05/edit-multiple-records-gridview-checkbox.html
0
 
LVL 23

Assisted Solution

by:Christopher Kile
Christopher Kile earned 1336 total points
ID: 38329534
GridViewRow  row = (GridViewRow)(GridView1.Rows(e.NewEditIndex));

Open in new window


No, you don't have to assign a new index, e.NewEditIndex is an integer.
0
 

Author Closing Comment

by:Rad1
ID: 38355090
Thank you!
0
 
LVL 23

Expert Comment

by:Christopher Kile
ID: 38355223
You are welcome :)
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…

621 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