Solved

How to find the value of the GridView row?

Posted on 2006-06-27
3
334 Views
Last Modified: 2008-02-01
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
Comment
Question by:chuang4630
  • 2
3 Comments
 
LVL 11

Accepted Solution

by:
TornadoV earned 500 total points
ID: 16993298
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
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 16994744
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
 
LVL 11

Expert Comment

by:TornadoV
ID: 16994784
acperkins, thanks for the info.
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

708 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now