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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T13:57:59+00:00 2026-06-04T13:57:59+00:00

I have a gridview that I am trying to loop through to get the

  • 0

I have a gridview that I am trying to loop through to get the values to update and store in my database. Gridview code:

<asp:GridView ID="GridView1" runat="server" AllowPaging="True" 
                AutoGenerateColumns="False" 
                Width="1020px" EnableTheming="True" PageSize="25" CellPadding="4" 
                ForeColor="#333333" >
                <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
                <Columns>
                    <asp:BoundField DataField="Column1" HeaderText="Col1" ReadOnly="True" >
                    <ItemStyle Width="35px" />
                    </asp:BoundField>
                    <asp:BoundField DataField="Column2" HeaderText="Col2" />
                    <asp:BoundField DataField="Column3" HeaderText="Col3" />
                    <asp:BoundField DataField="Column4" HeaderText="Col4" />
                    <asp:BoundField DataField="Column5" HeaderText="Col5" />
                    <asp:TemplateField HeaderText="Col6">
                        <EditItemTemplate>
                            <asp:Label ID="Label1" runat="server" Text='<%# Bind("Column6") %>'></asp:Label>
                        </EditItemTemplate>
                        <ItemTemplate>
                            <asp:Label ID="Label2" runat="server" Text="$"></asp:Label>&nbsp;
                            <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Column6", "{0:f}") %>' CssClass="boxright"></asp:TextBox>
                        </ItemTemplate>
                        <ItemStyle HorizontalAlign="Right" VerticalAlign="Middle" />
                    </asp:TemplateField>
                    <asp:BoundField DataField="Column7" ReadOnly="True" >
                    <ItemStyle Width="35px" />
                    </asp:BoundField>
                    </Columns>
                <EditRowStyle BackColor="#999999" />
                <FooterStyle BackColor="#003399" Font-Bold="True" ForeColor="White" />
                <HeaderStyle BackColor="#003399" Font-Bold="True" ForeColor="White" />
                <PagerSettings Mode="NextPreviousFirstLast" />
                <PagerStyle BackColor="#003399" ForeColor="White" HorizontalAlign="Left" />
                <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
                <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
                <SortedAscendingCellStyle BackColor="#E9E7E2" />
                <SortedAscendingHeaderStyle BackColor="#506C8C" />
                <SortedDescendingCellStyle BackColor="#FFFDF8" />
                <SortedDescendingHeaderStyle BackColor="#6F8DAE" />
            </asp:GridView>

I am using a button click event to trigger the stored sql procedure to update my table as follows…

Protected Sub btnB_Save_Click(sender As Object, e As EventArgs) Handles btnB_Save.Click
Dim gvRow As GridViewRow
    Dim str As String = ""
    For Each gvRow As GridViewRow In gv_Budgets.Rows
        str = ((str + gvRow.Cells(0).Text) + (gvRow.Cells(1).Text) + (gvRow.Cells(2).Text) + (gvRow.Cells(3).Text) + (gvRow.Cells(4).Text) + (gvRow.Cells(6).Text))
    Dim dtRow As TextBox = CType(gvRow.FindControl("TextBox1"), TextBox)
    Response.Write(dtRow.Text)

    dt = dal.ExecuteStoredProc(DAL.dbType.SqlServer, "UpdateData", "@col1", str + gvRow.Cells(0).Text, "@col2", str + gvRow.Cells(1).Text, "@col3", str + gvRow.Cells(2).Text, "@col4", str + gvRow.Cells(3).Text, "@col5", str + gvRow.Cells(4).Text, "@col6", dtRow.Text, "@col7", str + gvRow.Cells(6).Text, "@txt1", Textbox2.Text, "@txt2", Textbox3.Text)

    Next
End Sub 

However, I keep getting those blue syntax error lines under my “dt(datatable)” expression… Any ideas on how or why this is doing this?

  • 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-04T13:58:01+00:00Added an answer on June 4, 2026 at 1:58 pm

    Well the “Variable gvRow hides…” error is happening because you’ve declared gvRow outside the loop and then redeclared it in the definition of the loop.

    Dim gvRow As GridViewRow    ' First declaration
    Dim str As String = ""
    For Each gvRow As GridViewRow In gv_Budgets.Rows    ' Skip the "As GridViewRow here
    

    The other error is coming from your expression:

    dt = dal.ExecuteStoredProc( ...
    

    I’m assuming (because you don’t have it listed) that dt is some global variable of type DataTable somewhere. In this case it looks like your sProc is returning a string and attempting to insert it into a datatable object. Make sure your sProc returns a valid datatable. In the meantime you may try to insert the result into a string just to get things working until you can work that out.

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

Sidebar

Related Questions

I have a GridView on an ASP.NET page that I'm trying to bind to
I have a gridview that I'm trying to validate from code behind. In this
I have a ASP.net gridview that I am trying bind to. My DataSource has
I am trying to export a gridview's contents to excel. I have some code:
I am trying to make a small ASP.NET application where I have a GridView
I have a gridview that shows an image as part of one of its
I have a gridview that displays items details, I added two template fields one
I have a gridview that is only shown in a modal popup. right before
I have a GridView that I need to dynamically add TemplateField elements to. My
I have a gridview that is bound to a datasource on a Windows Form

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.