Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to find the value of the GridView row?

Posted on 2006-06-27
3
Medium Priority
?
349 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 2000 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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

609 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