2

I have a GridView. I have to collect the GridViewRow where checkbox is selected. How can I achieve it without any client side script? Please help me to get this done.

1
  • 1
    Posting the code what you have so far would make things easy for the people who want to answer you question. Commented Oct 23, 2010 at 16:24

3 Answers 3

4

If you are familiar with LINQ,you can get this something like

List<GridViewRow> rowCollection = 
                     GridView1.Rows
                     .OfType<GridViewRow>()
                     .Where(x => ((CheckBox)x.FindControl("chkRow")).Checked)
                     .Select(x => x).ToList();

All the best.

Sign up to request clarification or add additional context in comments.

Comments

1

Alternative old-school method is to iterate through the Rows collection of the grid with for or foreach cycle, find the checkboxes with the FindControl method and check their Checked property value.

Comments

1

Simple and easy to understand when you come back to it later.

 var selectedRows = (from GridViewRow row in GridView1.Rows
                    let cbx = (CheckBox)row.FindControl("CheckBox1")
                    where cbx.Checked
                    select row).ToList();

Bare in mind that for this to work I think you'll need to convert the column containing the checkbox into a template column.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.