Solved

How to find the value of the GridView row?

Posted on 2006-06-27
3
340 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

705 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