GridView does not show updated Records

G

Greg

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.
 
K

Ken Cox [Microsoft MVP]

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 said:
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.
 
T

Tom Biggar

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
 
P

pblack9455

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!
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,992
Messages
2,570,220
Members
46,807
Latest member
ryef

Latest Threads

Top