Solved

Problem with a Gridview control.  and a Variable.

Posted on 2013-06-18
3
313 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
3 Comments
 
LVL 35

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 12

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

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 …
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.
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

776 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