GridView does not show updated Records

Discussion in 'ASP .Net Datagrid Control' started by Greg, Oct 25, 2006.

  1. Greg

    Greg Guest

    Hi,

    This should be dirt simple... but clearly I am missing something. I
    have a GridView on an ASP Page. There are 5 fields on the page (2 of
    which can be updated), the user clicks edit, they go into edit mode,
    the user changes the data clicks updated... their old data is still
    there... I run some debug assertions and when I try and grab the value
    of the text fields I see the old values (not what is currenly in the
    textbox on the screen).

    I'm stumped... any ideas I am open to them.

    Greg

    Code (asp page)

    <asp:GridView ID="StatusGrid" runat="server" CellPadding="1"
    ForeColor="#333333" Width="100%" AllowSorting="True"
    OnRowCommand="StatusGrid_RowCommand" AutoGenerateColumns="False"
    OnRowEditing="StatusGrid_RowEditing"
    OnRowCreated="StatusGrid_RowCreated"
    OnRowDeleting="StatusGrid_RowDeleting"
    OnRowUpdating="StatusGrid_RowUpdating">
    <FooterStyle BackColor="#5D7B9D" Font-Bold="True"
    ForeColor="White" />
    <RowStyle BackColor="LightGray" ForeColor="#333333"
    HorizontalAlign="Center" Wrap="False" />
    <EditRowStyle BackColor="#999999" Font-Size="Medium" />
    <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True"
    ForeColor="#333333" />
    <PagerStyle BackColor="#284775" ForeColor="White"
    HorizontalAlign="Center" />
    <HeaderStyle BackColor="#5D7B9D" Font-Bold="True"
    ForeColor="ScrollBar" Font-Size="X-Small" />
    <AlternatingRowStyle BackColor="White" ForeColor="#284775"
    />
    <Columns>
    <asp:BoundField DataField="sts_id" HeaderText="sts_id"
    ReadOnly="True" SortExpression="sts_id">
    <ItemStyle HorizontalAlign="Left" />
    <HeaderStyle HorizontalAlign="Left" />
    </asp:BoundField>
    <asp:TemplateField HeaderText="sts_code">
    <ItemTemplate>
    <%# Eval("sts_code")%>
    </ItemTemplate>
    <ItemStyle HorizontalAlign="Left" />
    <HeaderStyle HorizontalAlign="Left" />
    <EditItemTemplate>
    <asp:textbox id="sts_code"
    text='<%#Eval("sts_code")%>'
    width="50"
    runat="server"/>
    </EditItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField HeaderText="sts_description">
    <ItemTemplate>
    <%# Eval("sts_description")%>
    </ItemTemplate>
    <ItemStyle HorizontalAlign="Left" />
    <HeaderStyle HorizontalAlign="Left" />
    <EditItemTemplate>
    <asp:textbox id="sts_description"
    text='<%#Eval("sts_description")%>'
    width="200"
    runat="server"/>
    </EditItemTemplate>
    </asp:TemplateField>
    <asp:BoundField DataField="sts_date_created"
    HeaderText="sts_date_created" SortExpression="sts_date_created"
    ReadOnly="True" />
    <asp:BoundField DataField="sts_date_modified"
    HeaderText="sts_date_modified" SortExpression="sts_date_modified"
    ReadOnly="True"/>
    <asp:CommandField ButtonType="Button" ShowDeleteButton="True"
    ShowEditButton="True" CausesValidation="False" InsertVisible="False" />
    </Columns>
    </asp:GridView>

    Code-Behind

    protected void StatusGrid_RowUpdating(object sender,
    GridViewUpdateEventArgs e)
    {

    GridViewRow row = StatusGrid.Rows[StatusGrid.EditIndex];

    TextBox Code = row.FindControl("sts_code") as TextBox;
    TextBox Description = row.FindControl("sts_description") as
    TextBox;

    e.NewValues["sts_code"] = Code.Text;
    e.NewValues["sts_description"] = Description.Text;

    }

    The Code.Text and Description.Text fields both have their old
    values????

    Thanks in advance.
    Greg, Oct 25, 2006
    #1
    1. Advertising

  2. Hi Greg,

    You haven't shown us the complete code behind so I can't tell much.

    However, the first thing I wonder is whether you are inadvertently rebinding
    to the original data on each postback?

    Ken
    Microsoft MVP [ASP.NET]
    Nipissing Township, Ontario, Canada



    "Greg" <> wrote in message
    news:...
    > Hi,
    >
    > This should be dirt simple... but clearly I am missing something. I
    > have a GridView on an ASP Page. There are 5 fields on the page (2 of
    > which can be updated), the user clicks edit, they go into edit mode,
    > the user changes the data clicks updated... their old data is still
    > there... I run some debug assertions and when I try and grab the value
    > of the text fields I see the old values (not what is currenly in the
    > textbox on the screen).
    >
    > I'm stumped... any ideas I am open to them.
    >
    > Greg
    >
    > Code (asp page)
    >
    > <asp:GridView ID="StatusGrid" runat="server" CellPadding="1"
    > ForeColor="#333333" Width="100%" AllowSorting="True"
    > OnRowCommand="StatusGrid_RowCommand" AutoGenerateColumns="False"
    > OnRowEditing="StatusGrid_RowEditing"
    > OnRowCreated="StatusGrid_RowCreated"
    > OnRowDeleting="StatusGrid_RowDeleting"
    > OnRowUpdating="StatusGrid_RowUpdating">
    > <FooterStyle BackColor="#5D7B9D" Font-Bold="True"
    > ForeColor="White" />
    > <RowStyle BackColor="LightGray" ForeColor="#333333"
    > HorizontalAlign="Center" Wrap="False" />
    > <EditRowStyle BackColor="#999999" Font-Size="Medium" />
    > <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True"
    > ForeColor="#333333" />
    > <PagerStyle BackColor="#284775" ForeColor="White"
    > HorizontalAlign="Center" />
    > <HeaderStyle BackColor="#5D7B9D" Font-Bold="True"
    > ForeColor="ScrollBar" Font-Size="X-Small" />
    > <AlternatingRowStyle BackColor="White" ForeColor="#284775"
    > />
    > <Columns>
    > <asp:BoundField DataField="sts_id" HeaderText="sts_id"
    > ReadOnly="True" SortExpression="sts_id">
    > <ItemStyle HorizontalAlign="Left" />
    > <HeaderStyle HorizontalAlign="Left" />
    > </asp:BoundField>
    > <asp:TemplateField HeaderText="sts_code">
    > <ItemTemplate>
    > <%# Eval("sts_code")%>
    > </ItemTemplate>
    > <ItemStyle HorizontalAlign="Left" />
    > <HeaderStyle HorizontalAlign="Left" />
    > <EditItemTemplate>
    > <asp:textbox id="sts_code"
    > text='<%#Eval("sts_code")%>'
    > width="50"
    > runat="server"/>
    > </EditItemTemplate>
    > </asp:TemplateField>
    > <asp:TemplateField HeaderText="sts_description">
    > <ItemTemplate>
    > <%# Eval("sts_description")%>
    > </ItemTemplate>
    > <ItemStyle HorizontalAlign="Left" />
    > <HeaderStyle HorizontalAlign="Left" />
    > <EditItemTemplate>
    > <asp:textbox id="sts_description"
    > text='<%#Eval("sts_description")%>'
    > width="200"
    > runat="server"/>
    > </EditItemTemplate>
    > </asp:TemplateField>
    > <asp:BoundField DataField="sts_date_created"
    > HeaderText="sts_date_created" SortExpression="sts_date_created"
    > ReadOnly="True" />
    > <asp:BoundField DataField="sts_date_modified"
    > HeaderText="sts_date_modified" SortExpression="sts_date_modified"
    > ReadOnly="True"/>
    > <asp:CommandField ButtonType="Button" ShowDeleteButton="True"
    > ShowEditButton="True" CausesValidation="False" InsertVisible="False" />
    > </Columns>
    > </asp:GridView>
    >
    > Code-Behind
    >
    > protected void StatusGrid_RowUpdating(object sender,
    > GridViewUpdateEventArgs e)
    > {
    >
    > GridViewRow row = StatusGrid.Rows[StatusGrid.EditIndex];
    >
    > TextBox Code = row.FindControl("sts_code") as TextBox;
    > TextBox Description = row.FindControl("sts_description") as
    > TextBox;
    >
    > e.NewValues["sts_code"] = Code.Text;
    > e.NewValues["sts_description"] = Description.Text;
    >
    > }
    >
    > The Code.Text and Description.Text fields both have their old
    > values????
    >
    > Thanks in advance.
    >
    Ken Cox [Microsoft MVP], Oct 26, 2006
    #2
    1. Advertising

  3. Greg

    Tom Biggar Guest

    Greg,
    did you ever get an answer to this problem? I am fighting the same
    thing. I see lots of people with the question but, so far, no answers.
    If you have a solution, please share it, and I will let you know if I
    find something.
    Tom



    *** Sent via Developersdex http://www.developersdex.com ***
    Tom Biggar, Nov 6, 2006
    #3
  4. Greg

    pblack9455 Guest

    Any solutions to this simple first use case? I've tried ObjectDataSource,
    but I need to bind to an ArrayList of Objects... the ArraList should
    initially be empty then allow me to populate it before the final 'accept'
    which then writes the ArrayList to the database.... I've been looking at this
    for what feels like days!

    "Tom Biggar" wrote:

    >
    > Greg,
    > did you ever get an answer to this problem? I am fighting the same
    > thing. I see lots of people with the question but, so far, no answers.
    > If you have a solution, please share it, and I will let you know if I
    > find something.
    > Tom
    >
    >
    >
    > *** Sent via Developersdex http://www.developersdex.com ***
    >
    pblack9455, Nov 26, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Luke Airig
    Replies:
    0
    Views:
    775
    Luke Airig
    Dec 31, 2003
  2. Dmitry Korolyov

    Datagrid not updated during delete, but updated during insert and update

    Dmitry Korolyov, Sep 22, 2003, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    403
    Dmitry Korolyov
    Sep 22, 2003
  3. Devendra

    GridView reload for the updated records.

    Devendra, Oct 13, 2005, in forum: ASP .Net Datagrid Control
    Replies:
    1
    Views:
    189
    Steven Cheng[MSFT]
    Oct 14, 2005
  4. Dan

    Delete records or update records

    Dan, May 10, 2004, in forum: ASP General
    Replies:
    1
    Views:
    455
    Ray at
    May 10, 2004
  5. greenflame
    Replies:
    6
    Views:
    142
    greenflame
    Jun 18, 2005
Loading...

Share This Page