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 6326493
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T17:06:07+00:00 2026-05-24T17:06:07+00:00

I have created datatable kept in session & assigned to gridview.I have to extract

  • 0

I have created datatable kept in session & assigned to gridview.I have to extract those records ,for that i have written code as follows but its giving value as null :

//To find gridview in Formview1
    GridView GridView1 = (GridView)Formview1.FindControl("GridView1");
    GridView1.DataSource = (DataTable)Session["tabdetails"];
    GridView1.DataBind();

    string str, str1, str2, str3, str4, str5, str6;
    for (int i = 0; i < GridView1.Rows.Count; i++)
    {
        str = GridView1.Rows[i].Cells[0].Text;
        str1 = GridView1.Rows[i].Cells[1].Text;
        str3 = GridView1.Rows[i].Cells[2].Text;
        str4 = GridView1.Rows[i].Cells[3].Text;
        str5 = GridView1.Rows[i].Cells[4].Text;
    }

Please suggest me to do right changes?
Thank you.
Asp.net c#

  • 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-05-24T17:06:07+00:00Added an answer on May 24, 2026 at 5:06 pm

    Use data keys to store the values that you need to retrieve.

    <asp:GridView ID="GridView1" runat="server" DataKeyNames="SomeColumnName, AnotherColumnName, SomeOtherColumnName" ... >
    

    And in your code behind:

    for (int i = 0; i < GridView1.Rows.Count; i++)
    {
        GridViewRow row = GridView1.Rows[i];
        string str = GridView1.DataKeys[row.RowIndex]["SomeColumnName"];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a GridView to which I bind a dataTable that I manually created.
I have a gridview that gets created in codebehind. In the below code, I
I have a Gridview which is binded to a datatable that I created. The
I have created a datatable and trying to insert that datatable through SqlBulkCopy but
I have a DataTable that I manually created and loaded with data using C#.
I have created a class that returns a datatable, when I use the class
Suppose I have the following code snippets, i.e. goo call foo, DataTable created by
I have created a gridview in code behind (as in its not physically present
I created a GridView in code with a DataTable as its data source which
Given a DataSet, I'm left joining DataTables[1-n] onto DataTable[0]. I have created a method

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.