Using this bit of code to try and return the value for a DataKey from a gridview based upon a button click. But, instead of giving me the ID for the row clicked, it's returning the number for it's row. So, if I click row 8, I'm getting a value of 8, instead
of the StreamingID of the row of data in row 8. What am I forgetting to do?
funluckykitt...
Participant
1469 Points
1547 Posts
Code returning row number, instead of DataKey value for the selected row...
Feb 21, 2013 07:27 PM|LINK
Using this bit of code to try and return the value for a DataKey from a gridview based upon a button click. But, instead of giving me the ID for the row clicked, it's returning the number for it's row. So, if I click row 8, I'm getting a value of 8, instead of the StreamingID of the row of data in row 8. What am I forgetting to do?
...lots of sql... this is where I get my data:
reader = comm.ExecuteReader();
gvStreaming.DataSource = reader;
gvStreaming.DataBind();
Then, on this button click, I never get the DataKeyName, it always returns the row number. ARGH.. very frustrating.
protected void btnSelectLP_Click(object sender, EventArgs e)
{
Button btn = sender as Button;
comm.Parameters.AddWithValue("SCID", gvStreaming.DataKeys[((GridViewRow)btn.NamingContainer).RowIndex].Values["StreamingID"].ToString());
..............
funluckykitt...
Participant
1469 Points
1547 Posts
Re: Code returning row number, instead of DataKey value for the selected row...
Feb 21, 2013 07:56 PM|LINK
Ah, found my answer on setting the datakeys in the codebehind..
http://forums.asp.net/t/1821577.aspx/1
Amy Peng - M...
Star
10199 Points
964 Posts
Microsoft
Re: Code returning row number, instead of DataKey value for the selected row...
Mar 07, 2013 05:23 AM|LINK
Hi,
Well Done!
It is kind of you to share your solution to us.
If you have any other problem, welcome to post it in the asp.net forums.
Best Regards,
Amy Peng
Feedback to us
Develop and promote your apps in Windows Store