Solved

Problem with a Gridview control.  and a Variable.

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

Business Impact of IT Communications

What are the business impacts of how well businesses communicate during an IT incident? Targeting, speed, and transparency all matter. Find out more in this infographic.

Question has a verified solution.

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

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

752 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