Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 129433
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T05:47:20+00:00 2026-05-11T05:47:20+00:00

Can anyone give me a short snippet that, given a GridView that was originally

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T05:47:20+00:00Added an answer on May 11, 2026 at 5:47 am

    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:

    <asp:GridView ID='GridView1' runat='server'     OnRowDataBound='GridView1_RowDataBound' AutoGenerateColumns='false'>     <Columns>         <asp:TemplateField HeaderText='String Value'>             <ItemTemplate>                 <%# Container.DataItem %>             </ItemTemplate>         </asp:TemplateField>     </Columns> </asp:GridView> 

    In your codebehind:

    protected void Page_Load(object sender, EventArgs e) {     string[] arrayOfStrings = new string[] { 'first', 'second', 'third' };     GridView1.DataSource = arrayOfStrings;     GridView1.DataBind(); }  protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) {     if (e.Row.RowType == DataControlRowType.DataRow) {         // e.Row is of type GridViewRow         // e.Row.DataItem contains the original value that was bound,         // but it is of type object so you'll need to cast it to a string.         string value = (string)e.Row.DataItem;     } } 

    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.

    List<string> names = new List<string>(new string[] { 'John', 'Frank', 'Bob' });  var bindableNames = from name in names                     select new {Names=name};  GridView1.DataSource = bindableNames.ToList(); 

    Then ‘Name’ would be the DataKeyName and BoundField DataField.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

can anyone give me short & simple code in c# to understand the MVP
Can anyone give me any pointers. I have a text file that contains dates
Can anyone give me the 411 on shopping carts? I have a client that
Can anyone give me some help with a design please? my users enter short
Can anyone give a short overview of the cases when and how an activity
Can anyone give me short description about his spring class org.springframework.jdbc.core.BatchPreparedStatementSetter ( JavaDoc API
Can anyone give me an example of these attributes in action: stroke-dasharray, stroke-linecap, stroke-linejoin
Can anyone give tell me how to search for a particular word in a
Can anyone give me a cross-browser supported solution for this problem?
Can anyone give me a hand with a touch of regex? I'm reading in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.