Can anyone give me a short snippet that, given a GridView that was originally bound to a simple string array, and given a GridViewRow row, will return the value that was bound to the row?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can’t, the only property System.String has is Length, and DataKeyName expects a property of the object you are binding to. To answer your second question, here is an example of getting the string value from a GridViewRow.
In your ASPX file:
In your codebehind:
The only reasonable workaround to the problem is to either create a wrapper class that has properties. Or if you are using .NET 3.5, you can use LINQ to make a temporary list which only includes your value as a property of the class. There is an example of this technique on MSDN Forums by vtcoder.
Then ‘Name’ would be the DataKeyName and BoundField DataField.