• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 354
  • Last Modified:

How to find the value of the GridView row?

The value of the GridView row is what I am looking for. I am implementing the CheckBox control column in the GridView control and need to take actions on those "checked" rows. The DataKeyNames is set to be the table primary key, which is what I am lookng for. When you select a row, you can always use SelectedValue to retrieve this key value. The question is what can you do to retrieve the key value while looping through the rows.

Thanks in advance.

0
chuang4630
Asked:
chuang4630
  • 2
1 Solution
 
TornadoVCommented:
ArrayList listOfIDsInCheckedRows = new ArrayList();
foreach (GridViewRow row in GridView1.Rows)
{
     if (((CheckBox)row.FindControl("YourCheckBoxColumnNameGoesHere")).Checked)
     {
           index = (int) GridView1.DataKeys[row.RowIndex].Value;
           listOfIDsInCheckedRows.Add(index);
      }
}

After this loop is done executing, your array list listOfIDsInCheckedRows should contain your IDs.

Hope this helps.
0
 
Anthony PerkinsCommented:
You will find experts more responsive if you take the time to attend to your open questions and not abandon them.  Here are listed all your open questions:

1 05/17/2006 500 How to use frame set in ASP.NET 2.0?  Open ASP.NET
2 05/19/2006 500 How to dump the document to the DIV dyna...  Open HTML
3 05/23/2006 500 What is the best practice to facilitate ...  Open ASP.NET
4 05/24/2006 500 How to solve the "double refresh" issue?  Open ASP.NET
5 05/24/2006 500 How to force the page refresh?  Open ASP.NET
6 05/26/2006 500 What is wrong with this code of selected...  Open ASP.NET
7 05/30/2006 500 How to create a "multi-column" list box?  Open ASP.NET
8 06/05/2006 500 Why there are errors in executing the SP...  Open ASP.NET
9 06/05/2006 500 How to handle the page view in GridView ...  Open ASP.NET
10 06/16/2006 500 How to open a new browser window without...  Open ASP.NET
11 06/16/2006 500 How to add the dynamic watermark?  Open ASP.NET
12 06/22/2006 500 How to find the desired element in the c...  Open ASP.NET
13 06/26/2006 500 How do I change the web site location in...  Open ASP.NET
14 06/27/2006 500 How to find the value of the GridView ro...  Open ASP.NET
15 06/27/2006 500 How to assign the table to the ViewState...  Open ASP.NET

Thanks.
0
 
TornadoVCommented:
acperkins, thanks for the info.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now