Link to home
Start Free TrialLog in
Avatar of bmanmike39
bmanmike39

asked on

Problem with a Gridview control. and a Variable.

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

Avatar of Miguel Oz
Miguel Oz
Flag of Australia image

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.
please post your code here so that we can review it and provide you the solution.
ASKER CERTIFIED SOLUTION
Avatar of guru_sami
guru_sami
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial