how to find row index in gridview rowdataboundAsk Questions

 Posted on 31/07/2018 12:04:48 PM

Trying to get current RowIndex from GridView's RowDataBound 

I have declared DataKeyNames as DataKeyNames = "Productid".

Now I am trying to get the current row index as:

protected void gvProductList_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        int p_ID = Int32.Parse(gvProductList.DataKeys[e.Row.RowIndex].Value.ToString());
        Session["productID"] = p_ID.ToString();
    }
}

But every time I am getting p_ID as 2, which is the ID of the last row in the table (I have only two records in the table).

I have tried almost every thing available on internet but ended up with the same result.

Please help me.

Thanks in advance

 

Share On: facebook gplus twitter
profile
Asked by Shailesh Chaudhary on 31/07/2018 12:04:48 PM Score: 681 points
Add Comment:
Submit

Comments

1 Answer

0 Corrected Answers
0
Profile
Answered by ketan Linbachiya on Aug 2 2018 8:47AM Score: 269 points
protected void gridView1_RowDataBound(Object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        int index = e.Row.RowIndex;
    }
}
Add Comment:

Post Your Answer

  •  
  •  

Existing Members

Sign in to your account
Email Address
Password
...or Join us
Download, Vote, Comment, Publish.
Full Name
Email Address
I have read and agree to the Terms of Service and Privacy Policy
Please subscribe me to the StoodQ newsletters
Guideline to answer a question:

Useful tips to submit your answer
Please read below guidelines before you submit your answer for question.

  • Read and understand question for which you are submitting your answer.
  • Try to avoid grammatical and spell mistake while answering.
  • Do not post any irrelevant information in your answer.
  • Explain your answer with example or any reference link to help who posted question.
  • If you find irrelevant question, please report it to support. Click here to contact support.
  • You agree to the privacy policy and terms of use to submit any contents.

Note: StoodQ is online developers community which helps developer for their difficulty, lets help them with your value contribution.