Solved

Problem with a Gridview control.  and a Variable.

Posted on 2013-06-18
3
340 Views
Last Modified: 2013-06-27
I need to get the productID out of a GridView control, and place it in a variable.  I thought i had it working by using the rowCreated event,  But i seem to get the previous rows ID  for instance if the id for row one is 7 and the id for row two is 8  and i click on row two i get 7 instead of 8 and so on threw the rest of the grid.  Can someone help me figure out what is going on and how to fix it.  Below is the code i have.

protected void GridView4_RowCreated(object sender, GridViewRowEventArgs e)
    {
        foreach (GridViewRow myRow in GridView4.Rows)
        {
            string intString = myRow.Cells[2].Text;
            Label22.Text = intString;
        }
        GridViewRow row = GridView4
        Label22.Text = row.Cells[2].Text;
    }

Open in new window

0
Comment
Question by:bmanmike39
[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
3 Comments
 
LVL 36

Expert Comment

by:Miguel Oz
ID: 39257933
How are you binding this gridview? (Please post markup/code)
Where is the ID allocated?

My issue will be that you need  to handle  RowDataBound event which occurs after data is bound to the grid rather than rowcreated event.
0
 
LVL 13

Expert Comment

by:Jitendra Patil
ID: 39258996
please post your code here so that we can review it and provide you the solution.
0
 
LVL 41

Accepted Solution

by:
guru_sami earned 500 total points
ID: 39260957
When you say "click on row two" I take  you are trying to get the id of the row you selected.
 Basically you need to grab the index of the row you clicked. There are several ways to do it.
- You can use GridViewSelectedIndexChanged
- Other ways
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

615 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