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

The Archive Base Latest Questions

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

I am using GridView in my application for populating datas. Is there any easy

  • 0

I am using GridView in my application for populating datas.

Is there any easy way to copy a gridview to datatable ?

Actually, in my GridView one of the control is textbox.
So I can edit that control at any time… What I need is on the button click whatever changes I made in GridView has to copy in one datatable…

I did this using the code,

dt = CType(Session('tempTable'), DataTable)  i = 0 For Each rows As GridViewRow In Grid1.Rows     Dim txt As TextBox     txt = CType(rows.FindControl('txt'), TextBox)     dt.Rows(i)(1) = txt.Text    i = i + 1  Next 

Here I am traversing through grid with the help of ‘for each’ loop.
I am worrying whether it effects performance?
Can you please tel me any other simple method to copy a GridView to a datatable

  • 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-11T00:47:22+00:00Added an answer on May 11, 2026 at 12:47 am

    html page look like,

                                <asp:GridView ID='Grid1' runat='server' AutoGenerateColumns='False' GridLines='None'>                                 <Columns>                                     <asp:TemplateField HeaderText='ID'>                                         <ItemTemplate>                                             <asp:Label ID='lbl1' runat='server' Text='<%#Bind('ID') %>' CssClass='rowHeader'></asp:Label>                                         </ItemTemplate>                                         <FooterTemplate>                                             <asp:TextBox ID='txt1' runat='server' Text='<%#Bind('ID') %>'></asp:TextBox>                                         </FooterTemplate>                                     </asp:TemplateField>                                     <asp:TemplateField HeaderText='Description'>                                         <ItemTemplate>                                             <asp:TextBox ID='txt' runat='server' Text='<%#Bind('Description') %>'></asp:TextBox>                                         </ItemTemplate>                                         <FooterTemplate>                                             <asp:TextBox ID='txt2' runat='server' Text='<%#Bind('Description') %>'></asp:TextBox>                                         </FooterTemplate>                                     </asp:TemplateField>                                     <asp:TemplateField HeaderText='Comments'>                                         <ItemTemplate>                                             <asp:Label ID='Comments' runat='server' Text='<%#Bind('Comments') %>'></asp:Label>                                         </ItemTemplate>                                         <FooterTemplate>                                             <asp:DropDownList ID='Drop1' runat='server'>                                                 <asp:ListItem>v1</asp:ListItem>                                                 <asp:ListItem>v2</asp:ListItem>                                             </asp:DropDownList>                                         </FooterTemplate>                                     </asp:TemplateField>                                 </Columns>                             </asp:GridView>                              <asp:Button ID='btnAdd' runat='server' Text='Add' />                             <asp:Button ID='btnSave' runat='server' Text='Save' /> 

    on page load,

    conn = New OleDb.OleDbConnection(‘Provider = Microsoft.Jet.OLEDB.4.0; Data Source = D:\GDD_Work\Employee.mdb’)

        If Not Page.IsPostBack Then          ViewState('intCount') = 0         Session('blnFlag') = False          Dim Cmd As New OleDb.OleDbDataAdapter('Select * from Emp', conn)         Cmd.Fill(ds, 'Employee')          Grid1.DataSource = ds.Tables('Employee')         Grid1.DataBind()          Session('intOldCount') = ds.Tables('Employee').Rows.Count         Session('tempTable') = ds.Tables('Employee') 

    on add button click,

    If Session(‘blnFlag’) = False Then Session(‘blnFlag’) = True Else getFooter() End If

        Grid1.FooterRow.Visible = True 

    on save button click,

    Dim intOldCount As Integer Dim intNewCount As Integer Dim dt As New DataTable Dim strQuery As String intOldCount = CType(Session(‘intOldCount’), Integer) If Session(‘blnFlag’) = True Then

            getFooter()         dt = CType(Session('tempTable'), DataTable)         intNewCount = dt.Rows.Count          If intOldCount = intNewCount Then             Dim tx1 As TextBox             Dim tx2 As TextBox             Dim drp As DropDownList             tx1 = CType(Grid1.FooterRow.FindControl('txt1'), TextBox)             tx2 = CType(Grid1.FooterRow.FindControl('txt2'), TextBox)             drp = CType(Grid1.FooterRow.FindControl('Drop1'), DropDownList)              strQuery = 'INSERT INTO Emp (ID,Description,Comments) values ('' + tx1.Text + '','' + tx2.Text + '','' + drp.SelectedValue + '')'             Dim Cmd As New OleDb.OleDbCommand(strQuery, conn)             conn.Open()             Cmd.ExecuteNonQuery()             conn.Close()          Else             For i = intOldCount To intNewCount - 1                 Dim strId As String                 Dim strDesc As String                 Dim strComm As String                 strId = dt.Rows(i)(0).ToString()                 strDesc = dt.Rows(i)(1).ToString()                 strComm = dt.Rows(i)(2).ToString()                  strQuery = 'INSERT INTO Emp (ID,Description,Comments) values ('' + strId + '','' + strDesc + '','' + strComm + '')'                 Dim Cmd As New OleDb.OleDbCommand(strQuery, conn)                 conn.Open()                 Cmd.ExecuteNonQuery()                 conn.Close()             Next         End If          For i = 0 To intOldCount - 1             Dim strId As String             Dim strDesc As String             strId = dt.Rows(i)(0).ToString()             strDesc = dt.Rows(i)(1).ToString()             strQuery = 'update Emp set Description = '' + strDesc + '' where ID = '' + strId + '''              Dim Cmd1 As New OleDb.OleDbCommand(strQuery, conn)             conn.Open()             Cmd1.ExecuteNonQuery()             conn.Close()         Next          ds = New DataSet()         Dim CmdData As New OleDb.OleDbDataAdapter('Select * from Emp', conn)         CmdData.Fill(ds, 'Employee')         Grid1.DataSource = ds.Tables('Employee').DefaultView         Grid1.DataBind()          Session('blnFlag') = False     Else         dt = CType(Session('tempTable'), DataTable)         i = 0         For Each rows As GridViewRow In Grid1.Rows             Dim txt As TextBox             txt = CType(rows.FindControl('txt'), TextBox)             dt.Rows(i)(1) = txt.Text             i = i + 1         Next         Session('tempTable') = dt          For i = 0 To intOldCount - 1             Dim strId As String             Dim strDesc As String             strId = dt.Rows(i)(0).ToString()             strDesc = dt.Rows(i)(1).ToString()             strQuery = 'update Emp set Description = '' + strDesc + '' where ID = '' + strId + '''              Dim Cmd1 As New OleDb.OleDbCommand(strQuery, conn)             conn.Open()             Cmd1.ExecuteNonQuery()             conn.Close()         Next          Grid1.DataSource = dt.DefaultView         Grid1.DataBind()      End If 

    im using one function like,

    Public Function getFooter() Dim tx1 As TextBox Dim tx2 As TextBox Dim drp As DropDownList tx1 = CType(Grid1.FooterRow.FindControl(‘txt1’), TextBox) tx2 = CType(Grid1.FooterRow.FindControl(‘txt2’), TextBox) drp = CType(Grid1.FooterRow.FindControl(‘Drop1’), DropDownList)

        Dim dr As DataRow     Dim dt As DataTable     dt = CType(Session('tempTable'), DataTable)      dr = dt.NewRow()     dr('ID') = tx1.Text     dr('Description') = tx2.Text     dr('Comments') = drp.SelectedValue     dt.Rows.Add(dr)      i = 0     For Each rows As GridViewRow In Grid1.Rows         Dim txt As TextBox         txt = CType(rows.FindControl('txt'), TextBox)         dt.Rows(i)(1) = txt.Text         i = i + 1     Next      Grid1.DataSource = dt.DefaultView     Grid1.DataBind()      Session('tempTable') = dt End Function 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 122k
  • Answers 122k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer There's nothing in the Framework, I believe. You can do… May 12, 2026 at 12:52 am
  • Editorial Team
    Editorial Team added an answer By default diff only prints a single line for each… May 12, 2026 at 12:52 am
  • Editorial Team
    Editorial Team added an answer try adding evt.consume() after your call to sendMessage() private void… May 12, 2026 at 12:52 am

Related Questions

I'm attempting to pull some data from a SQLite database so that I can
I have a web application that I am working on(ASP.NET 2.0 & C#). In
In one of my ASP.NET Web Applications, I am using a BulkEditGridView (a GridView
I tried to ask this question previously howver I did not recieve the correct

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.