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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T04:15:58+00:00 2026-06-15T04:15:58+00:00

Coding Problem: Converting a Asp.Net GridView that has controls back into a data table

  • 0

Coding Problem:

Converting a Asp.Net GridView that has controls back into a data table

Real World Problem:

Google did not have any really useful answers I could find and implement

Asp.Net GridView:

<asp:GridView ID="gvCompanies" runat="server" AutoGenerateColumns="False" AllowSorting="True" OnSorting="gridView_Sorting">
            <Columns>
            <asp:TemplateField HeaderText = "Comapny Id"><ItemTemplate><%# Eval("Company Id")%></ItemTemplate></asp:TemplateField>
            <asp:TemplateField HeaderText = "New Company Id"><ItemTemplate><asp:TextBox ID="TextBox5" runat ="server"></asp:TextBox></ItemTemplate></asp:TemplateField>
            <asp:TemplateField HeaderText = "Company Name"><ItemTemplate><asp:TextBox ID="TextBox6" runat ="server"></asp:TextBox></ItemTemplate></asp:TemplateField>
            <asp:TemplateField HeaderText = "Branch Id"><ItemTemplate><asp:TextBox ID="TextBox7" runat ="server"></asp:TextBox></ItemTemplate></asp:TemplateField>
            <asp:TemplateField HeaderText = "Location Id"><ItemTemplate><asp:TextBox ID="TextBox8" runat ="server"></asp:TextBox></ItemTemplate></asp:TemplateField>
            <asp:TemplateField HeaderText = "Location Name"><ItemTemplate><asp:TextBox ID="TextBox9" runat ="server"></asp:TextBox></ItemTemplate></asp:TemplateField>
            <asp:TemplateField HeaderText = "Prefix"><ItemTemplate><asp:TextBox ID="TextBox10" runat ="server" ></asp:TextBox></ItemTemplate></asp:TemplateField>
            <asp:TemplateField HeaderText = "Sort"><ItemTemplate><asp:TextBox ID="TextBox11" runat ="server"></asp:TextBox></ItemTemplate></asp:TemplateField>
            <asp:TemplateField HeaderText = "Cash In Transit"><ItemTemplate><asp:TextBox ID="TextBox12" runat ="server"></asp:TextBox></ItemTemplate></asp:TemplateField>
            <asp:TemplateField HeaderText = "Cash Sub In Transit"><ItemTemplate><asp:TextBox ID="TextBox13" runat ="server"></asp:TextBox></ItemTemplate></asp:TemplateField>
            <asp:TemplateField HeaderText = "Cash Account"><ItemTemplate><asp:TextBox ID="TextBox14" runat ="server"></asp:TextBox></ItemTemplate></asp:TemplateField>
            <asp:TemplateField HeaderText = "Cash Sub Account"><ItemTemplate><asp:TextBox ID="TextBox15" runat ="server"></asp:TextBox></ItemTemplate></asp:TemplateField>
            <asp:TemplateField HeaderText = "Payment Method"><ItemTemplate><asp:TextBox ID="TextBox16" runat ="server"></asp:TextBox></ItemTemplate></asp:TemplateField>
            <asp:TemplateField HeaderText = "AppDB"><ItemTemplate><%# Eval("AppDB")%></ItemTemplate></asp:TemplateField>
            </Columns>
            </asp:GridView
  • 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-15T04:16:00+00:00Added an answer on June 15, 2026 at 4:16 am

    Solution:

    1. gvCompanies is the GridView
    2. dtCompanies was the original DataTable
    3. Can add more if else for different control types

      protected DataTable ConvertToDataTable()
      {
          DataTable TempTable = new DataTable();
          TempTable = dtCompanies.Clone();
      
          foreach (GridViewRow row in gvCompanies.Rows)
          {
               DataRow TempRow = TempTable.NewRow();
      
               for (int i = 0; i < row.Cells.Count; i++)
               {
                   if (row.Cells[i].Controls[0].GetType().Equals(typeof(DataBoundLiteralControl)))
                   {
                       TempRow[i] = ((DataBoundLiteralControl)row.Cells[i].Controls[0] as DataBoundLiteralControl).Text;
                   }
                   else if (row.Cells[i].Controls[0].GetType().Equals(typeof(TextBox)))
                   {
                       TempRow[i] = ((TextBox)row.Cells[i].Controls[0]).Text;
                   }
               }
               TempTable.Rows.Add(TempRow);
          }
          return TempTable;
      }
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a task at work that involves converting legacy SGM files into XML.
CHANGE: I have determined the problem has nothing to do with the coding. However
I have some problem converting my data from an plist to objects. The plist
The actual problem I was originally doing was converting a hash of arrays into
I'm after some guidance on how to approach coding a problem, I don't want
My problem is, I did coding for a sprite. It should change it should
I have a problem in my coding which was working fine with an older
I see this problem on and off again in my PHP coding, and I've
i had a problem on confusing how to put ontouch inside my coding because
I am coding this layout as a wordpress theme and having a slight problem

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.