Click here to Skip to main content
15,887,676 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
This code for getting checked rows in gridview

C#
private List<GridViewRow> GetCheckedRows(GridView grd)
    {
        List<GridViewRow> result = new List<GridViewRow>();
        foreach (GridViewRow gridRow in grd.Rows)
        {
            CheckBox chkBox = gridRow.FindControl("checkBoxName") as CheckBox ;
            if (chkBox != null && chkBox.Checked  )
            {
                result.Add(gridRow);
            }
        }
        return result;
    }


When I run it in the browser it dose not give me any response

How can I improve it to work?

and should be put in gridview event ?

Thank you
Posted
Updated 10-Apr-11 5:23am
v2

1 solution

When I run it in the browser it dose not give me any response
And what kind of response you are expecting from the above code?
All your code does is creates a set of GridRows whose checkbox was found as checked. Done.

Based on what the method looks like doing, all is fine and does not need any change/improvement.


It might be that you are looking for somthing else but you totally failed in expressing on what you were trying and needed here. For now, the code is fine and does not look like an issue in it.
 
Share this answer
 
Comments
dedoooo 10-Apr-11 12:27pm    
I want from the code to display the checked items in the page in order to print out in paper.
Sandeep Mewara 10-Apr-11 12:38pm    
Well, your code has given you the rows that was selected. Now, use the List and do the rest - code for it.
dedoooo 10-Apr-11 12:46pm    
What is the List? Did you mean an array?

Sandeep Mewara 10-Apr-11 12:50pm    
Is it a copied code from somewhere? I ask as, this is your code where you made a method that returns "List<gridviewrow>" => Based on logic, a list of rows that has it's checkbox checked.

Not sure now, what you know, wrote and trying here, seriously.
Espen Harlinn 10-Apr-11 12:39pm    
I believe I mentioned something about part of the code running in the browser, and part of it running on the server. Your c# codebehind runs on the server, so you have to do something that triggers communication between what you've got in the browser and your serverside code ... like a postback

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900