Solved

Problem with a Gridview control.  and a Variable.

Posted on 2013-06-18
3
300 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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
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.

706 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

18 Experts available now in Live!

Get 1:1 Help Now