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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:53:26+00:00 2026-05-26T00:53:26+00:00

So what’s happening is that I click the Edit button, type the updated values

  • 0

So what’s happening is that I click the Edit button, type the updated values and hit Update. But the code-behind gets the original values not the updated values. I can’t figure out why. It’s always worked before.

Markup

<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" 
     CellPadding="7" ForeColor="#333333" GridLines="None" Font-Size="Small"
     ShowFooter="True" DataKeyNames="CapID">
  <AlternatingRowStyle BackColor="White" />
  <Columns>
    <asp:TemplateField HeaderText="AllocationId">
      <ItemTemplate>
        <asp:Label ID="show" runat="server" Text='<%# Eval("CapID") %>' />
      </ItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField HeaderText="Reference Number">
      <ItemTemplate>
        <asp:Label ID="showRefNo" runat="server" Text='<%# Eval("RefNo") %>'/>
      </ItemTemplate>
      <EditItemTemplate>
        <asp:TextBox runat="server" ID="EditRefNo" 
                     Text='<%# Bind("RefNo") %>'/>
      </EditItemTemplate>
      <FooterTemplate>
        <asp:TextBox runat="server" ID="InsertRefNo" 
                     Text='<%# Bind("RefNo") %>'/>
      </FooterTemplate>
    </asp:TemplateField>
    <asp:TemplateField HeaderText="Resource">
      <ItemTemplate>
        <asp:Label ID="showResource" runat="server" 
                   Text='<%# Eval("Resource") %>'/>
      </ItemTemplate>
      <EditItemTemplate>
        <asp:TextBox runat="server" ID="EditResource" 
                     Text='<%# Bind("Resource") %>'/>
      </EditItemTemplate>
      <FooterTemplate>
        <asp:TextBox runat="server" ID="InsertResource" 
                     Text='<%# Bind("Resource") %>'/>
      </FooterTemplate>
    </asp:TemplateField>
    <!-- and so on... -->
  </Columns>
  <!-- styles etc -->         
  <EmptyDataTemplate>
    Ref Num:&nbsp;<asp:TextBox ID="newRefNo" runat="server"/>
    Resource:&nbsp;<asp:TextBox ID="newResource" runat="server"/>
    Hours Allocated:&nbsp;<asp:TextBox ID="newHours" runat="server"/>
    Week Offset:&nbsp;<asp:TextBox ID="newOffset" runat="server"/>
    <asp:Button runat="server" ID="NewDataInsert" 
                CommandName="NewDataInsert" Text="Insert"/>
  </EmptyDataTemplate>  
</asp:GridView>

Code Behind

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) 
    Handles Me.Load
        If Not IsPostBack Then   
            GridView1_DataBind()
            GridView2_DataBind()
        End If
End Sub


Protected Sub GridView2_RowUpdating(ByVal sender As Object, ByVal e As
    GridViewUpdateEventArgs) Handles GridView2.RowUpdating

    Dim capID As Label = GridView2.Rows(e.RowIndex).Cells(0)
        .FindControl("show")
    Dim refNo As TextBox = GridView2.Rows(e.RowIndex).Cells(1)
        .FindControl("EditRefNo")
    Dim resource As TextBox = 
        GridView2.Rows(e.RowIndex).Cells(2).FindControl("EditResource")
    Dim hours As TextBox = 
        GridView2.Rows(e.RowIndex).Cells(3).FindControl("EditHours")
    Dim offSet As TextBox =
        GridView2.Rows(e.RowIndex).Cells(4).FindControl("EditOffset")

    Dim newResAlloc As DataTable = resourceInfo.loadResAllocations
    Dim updateRows As DataRow() = 
        newResAlloc.Select("CapID = " & "'" & capID.Text & "'")

    If (Not updateRows Is Nothing) And updateRows.Length > 0 Then
        For Each updRow As DataRow In updateRows
            updRow.BeginEdit()

            updRow.Item("Refno") = refNo.Text
            updRow.Item("Resource") = resource.Text
            updRow.Item("Hours") = hours.Text
            updRow.Item("Offset") = offSet.Text

            updRow.EndEdit()
        Next
    End If

    resourceInfo.updateResAllocations(newResAlloc)

    GridView2.EditIndex = -1
    GridView2_DataBind()
End Sub
  • 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-26T00:53:27+00:00Added an answer on May 26, 2026 at 12:53 am

    The problem was that my RowCommand method was calling the DataBind

    Wrong way:

    Protected Sub GridView2_RowCommand(ByVal sender As Object, ByVal e As GridViewCommandEventArgs) Handles GridView2.RowCommand
    
        If e.CommandName = "NewDataInsert" Then
    
            Dim refNo As TextBox = GridView2.Controls(0).Controls(0).FindControl("NewRefNo")
            Dim resource As TextBox = GridView2.Controls(0).Controls(0).FindControl("NewResource")
            Dim hours As TextBox = GridView2.Controls(0).Controls(0).FindControl("NewHours")
            Dim offset As TextBox = GridView2.Controls(0).Controls(0).FindControl("NewOffset")
    
            Dim newResAlloc As DataTable = resourceInfo.loadResAllocations
            Dim newAllocRow As DataRow = newResAlloc.NewRow
            newAllocRow.ItemArray = New Object() {Nothing, refNo.Text, resource.Text, hours.Text, offset.Text}
            newResAlloc.Rows.Add(newAllocRow)
    
            resourceInfo.updateResAllocations(newResAlloc)
    
        ElseIf e.CommandName = "InsertNew" Then
    
            Dim refNo As TextBox = GridView2.FooterRow.FindControl("InsertRefNo")
            Dim resource As TextBox = GridView2.FooterRow.FindControl("InsertResource")
            Dim hours As TextBox = GridView2.FooterRow.FindControl("InsertHours")
            Dim offset As TextBox = GridView2.FooterRow.FindControl("InsertOffset")
    
            Dim newResAlloc As DataTable = resourceInfo.loadResAllocations
            Dim newAllocRow As DataRow = newResAlloc.NewRow
            newAllocRow.ItemArray = New Object() {Nothing, refNo.Text, resource.Text, hours.Text, offset.Text}
            newResAlloc.Rows.Add(newAllocRow)
    
            resourceInfo.updateResAllocations(newResAlloc)
    
    
        End If
    
        GridView2_DataBind() 'Culprit
    End Sub
    

    Right way:

    Protected Sub GridView2_RowCommand(ByVal sender As Object, ByVal e As GridViewCommandEventArgs) Handles GridView2.RowCommand
    
        If e.CommandName = "NewDataInsert" Then
    
            Dim refNo As TextBox = GridView2.Controls(0).Controls(0).FindControl("NewRefNo")
            Dim resource As TextBox = GridView2.Controls(0).Controls(0).FindControl("NewResource")
            Dim hours As TextBox = GridView2.Controls(0).Controls(0).FindControl("NewHours")
            Dim offset As TextBox = GridView2.Controls(0).Controls(0).FindControl("NewOffset")
    
            Dim newResAlloc As DataTable = resourceInfo.loadResAllocations
            Dim newAllocRow As DataRow = newResAlloc.NewRow
            newAllocRow.ItemArray = New Object() {Nothing, refNo.Text, resource.Text, hours.Text, offset.Text}
            newResAlloc.Rows.Add(newAllocRow)
    
            resourceInfo.updateResAllocations(newResAlloc)
    
            GridView2_DataBind()  'Only called if IF is true
    
        ElseIf e.CommandName = "InsertNew" Then
    
            Dim refNo As TextBox = GridView2.FooterRow.FindControl("InsertRefNo")
            Dim resource As TextBox = GridView2.FooterRow.FindControl("InsertResource")
            Dim hours As TextBox = GridView2.FooterRow.FindControl("InsertHours")
            Dim offset As TextBox = GridView2.FooterRow.FindControl("InsertOffset")
    
            Dim newResAlloc As DataTable = resourceInfo.loadResAllocations
            Dim newAllocRow As DataRow = newResAlloc.NewRow
            newAllocRow.ItemArray = New Object() {Nothing, refNo.Text, resource.Text, hours.Text, offset.Text}
            newResAlloc.Rows.Add(newAllocRow)
    
            resourceInfo.updateResAllocations(newResAlloc)
    
            GridView2_DataBind()  'Only called if IF is true
        End If
    
    
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I've got a string that has curly quotes in it. I'd like to replace
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I need to clean up various Word 'smart' characters in user input, including but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function

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.