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

  • Home
  • SEARCH
  • 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 7900539
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T08:59:47+00:00 2026-06-03T08:59:47+00:00

I am trying to code a sort routine against a dynamicaly populated gridview names

  • 0

I am trying to code a sort routine against a dynamicaly populated gridview names Users. I have a syntax error in the C# code where I am trying to populate a column in a row of a the datatable.

    for (int j = 0; j <= Users.Rows.Count - 1; j++) 
    { 
        DataRow dr = default(DataRow); 
        GridViewRow row = Users.Rows[j]; 
        dr = dt.NewRow(); 
        DataView dvUsers = new DataView(dt); 

        for (int i = 0; i <= row.Cells.Count - 1; i++) 
        { 
            dr.Item(i) = row.Cells[i].Text; 
        } 

        dt.Rows.Add(dr); 
    } 

Error message:

System.Data.DataRow does not contain a definition for “Item”

Can someone help with the correct syntax to assign this value to the datarow?

I am new to C#

thank you,

  • 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. Editorial Team
    Editorial Team
    2026-06-03T08:59:48+00:00Added an answer on June 3, 2026 at 8:59 am

    You just need to change the line

    dr.Item(i) = row.Cells[i].Text; 
    

    to

    dr[i] = row.Cells[i].Text; 
    

    Assuming the columns in the data table match the ordering of the cells in the table.

    () are used to call methods, while [] indicates an indexer. This is the reason for the compile error. There isn’t a method Item on DataRow, it is an indexer.

    EDIT

    Changed dr.Item[i] to dr[i]. As explained in the comments, Item is the default indexer, so you don’t specify the property, the index provided to the object itself will be applied to the Item indexer.

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

Sidebar

Related Questions

I have been trying to code merge sort, without creating additional arrays for keeping
I have a program that is trying to sort some names alphabetically. I run
I'm trying to bubble sort a character array in alphabetic order. My code is
I´m trying to code a tooltip (Yes I know, I have my reasons to
I am trying to code a global lookup table of sorts. I have game
I am trying to code an all in one HTML/PHP contact from with error
I have a legacy code to maintain and while trying to understand the logic
I am trying to implement Quick Sort algorithm. Following code works for unique elements
we're trying to sort out some conventions for handling dependencies with code checked into
I'm trying to color code text in a legend. (Since I'm trying to sort

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.