473,473 Members | 1,984 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Editable DataGrid Shows Old Values "After" Update

Hello, I am using an editable datagrid. After I save the changes the
datagrid shows the old values.

I've read the posts about the Page_Load and not binding the datagrid
each time. The SQL that is being sent to the database is correct and
the changes are eventually being made. If I refresh the page after the
update then the new values appear.

I noticed that when I put a breakpoint in my update handler everything
works fine. When I take out the breakpoint, I get the old values. It's
like the update isn't happening fast enough. I'm updating then
selecting before the update is finished. Or am I way off base and I'm
doing something else wrong?

Help.

Thanks in advance,
Kevin
Nov 18 '05 #1
3 4918
Do you rebind the grid *after* update has been done? Post some code.

--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist
"Kevin Pedersen" <ke************@hotmail.com> wrote in message
news:20************************@posting.google.com ...
Hello, I am using an editable datagrid. After I save the changes the
datagrid shows the old values.

I've read the posts about the Page_Load and not binding the datagrid
each time. The SQL that is being sent to the database is correct and
the changes are eventually being made. If I refresh the page after the
update then the new values appear.

I noticed that when I put a breakpoint in my update handler everything
works fine. When I take out the breakpoint, I get the old values. It's
like the update isn't happening fast enough. I'm updating then
selecting before the update is finished. Or am I way off base and I'm
doing something else wrong?

Help.

Thanks in advance,
Kevin

Nov 18 '05 #2
Kevin Pedersen wrote:
Hello, I am using an editable datagrid. After I save the changes the
datagrid shows the old values.


Once you've acquired the row to be updated, follow these steps:

1) Call DatRow.BeginEdit()
2) Change the values in the DataRow
3) Call DataRow.EndEdit()
4) Connect to the database
5) Call DataAdapter.Update(DataTable)
6) Call DataTable.AcceptChanges()
7) Rebind your DataGrid

--
There are 10 kinds of people. Those who understand binary and those who
don't.

http://code.acadx.com
(Pull the pin to reply)
Nov 18 '05 #3
Here's the code. At least the stuff I thought was relevant.

<asp:datagrid id="details" runat="server"
visible="False"
datakeyfield="entity_id"
autogeneratecolumns="False"
headerstyle-font-bold="True"
font-size="10pt"
font-name="Verdana"
oneditcommand="onEdit"
oncancelcommand="onCancel"
onupdatecommand="onUpdate"
<columns>
<asp:boundcolumn headertext="ID" datafield="entity_id"
readonly="True" />

<asp:templatecolumn headertext="Name">
<itemtemplate>
<asp:label runat="server" id="lblName"
text='<%# DataBinder.Eval( Container.DataItem, "entity_name"
) %>' />
</itemtemplate>

<edititemtemplate>
<asp:textbox id="txtName" runat="server" font-name="Verdana"
text='<%# DataBinder.Eval( Container.DataItem, "entity_name"
) %>' />
</edititemtemplate>
</asp:templatecolumn>

<asp:templatecolumn headertext="Number">
<itemtemplate>
<asp:label id="lblNumber" runat="server"
text='<%# DataBinder.Eval( Container.DataItem,
"street_number" ) %>' />
</itemtemplate>

<edititemtemplate>
<asp:dropdownlist id="ddlNumber" runat="server"
datasource='<%# getStreetNumbers() %>'
datatextfield="street_number"
datavaluefield="id"
onprerender="setItemIndex" />
</edititemtemplate>
</asp:templatecolumn>

<asp:templatecolumn runat="server" headertext="Street">
<itemtemplate>
<asp:label runat="server" text='<%#
DataBinder.Eval( Container.DataItem, "street_name" ) + " "
+
DataBinder.Eval( Container.DataItem, "street_type" ) %>' />
</itemtemplate>
</asp:templatecolumn>

<asp:templatecolumn runat="server" headertext="Phone 1">
<itemtemplate>
<asp:label id="lblPhone1" runat="server"
text='<%# DataBinder.Eval( Container.DataItem, "phone1" )
%>' />
</itemtemplate>

<edititemtemplate>
<asp:textbox id="txtPhone1" runat="server"
text='<%# DataBinder.Eval( Container.DataItem, "phone1" )
%>'
width="80" />
</edititemtemplate>
</asp:templatecolumn>

<asp:templatecolumn runat="server" headertext="Phone 2">
<itemtemplate>
<asp:label id="lblPhone2" runat="server"
text='<%# DataBinder.Eval( Container.DataItem, "phone2" )
%>' />
</itemtemplate>

<edititemtemplate>
<asp:textbox id="txtPhone2" runat="server"
text='<%# DataBinder.Eval( Container.DataItem, "phone2" )
%>'
width="80" />
</edititemtemplate>
</asp:templatecolumn>

<asp:templatecolumn runat="server" headertext="Type">
<itemtemplate>
<asp:label id="lblType" runat="server"
text='<%# DataBinder.Eval( Container.DataItem, "type" ) %>'
/>
</itemtemplate>

<edititemtemplate>
<asp:dropdownlist id="ddlType" runat="server"
datasource='<%# getTypes() %>'
datatextfield="type"
datavaluefield="id"
onprerender="setItemIndex"
/>
</edititemtemplate>
</asp:templatecolumn>

<asp:templatecolumn runat="server" headertext="Sub Type 1">
<itemtemplate>
<asp:label id="lblSubType1" runat="server"
text='<%# DataBinder.Eval( Container.DataItem, "subtype1" )
%>' />
</itemtemplate>

<edititemtemplate>
<asp:dropdownlist id="ddlSubType1" runat="server"
datasource='<%# getSubTypes() %>'
datatextfield="type"
datavaluefield="id"
onprerender="setItemIndex"
/>
</edititemtemplate>
</asp:templatecolumn>

<asp:templatecolumn runat="server" headertext="Sub Type 2">
<itemtemplate>
<asp:label id="lblSubType2" runat="server"
text='<%# DataBinder.Eval( Container.DataItem, "subtype2" )
%>' />
</itemtemplate>

<edititemtemplate>
<asp:dropdownlist id="ddlSubType2" runat="server"
datasource='<%# getSubTypes() %>'
datatextfield="type"
datavaluefield="id"
onprerender="setItemIndex"
/>
</edititemtemplate>
</asp:templatecolumn>

<asp:editcommandcolumn
edittext="Edit"
canceltext="Cancel"
updatetext="Save" />

<asp:buttoncolumn
buttontype="LinkButton"
commandname="Delete"
text="Delete" />
</columns>
</asp:datagrid>

private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
if( !IsPostBack )
{
streetId = "1";
bindGrid();
}
else {
// Get the current selection from the list box
streetId = streetList.selectedItemValue == "" ? "1" :
streetList.selectedItemValue;

// Show results
details.Visible = true;
street_image.Visible = true;
}
}

private void bindGrid()
{
string connectString =
System.Configuration.ConfigurationSettings.AppSett ings[
"connectString" ];

// Create connection and set connection string
OleDbConnection cnn = new OleDbConnection( connectString );

string sql = "SELECT entity.id AS entity_id, entity.name AS
entity_name, " +
"block_address.id AS block_address_id,
block_address.street_number, street.name AS street_name, " +
"street.type AS street_type, entity.phone1, entity.phone2, "
+
"(SELECT type FROM entity_type WHERE id = entity.type ) AS
type, " +
"(SELECT type FROM entity_sub_type WHERE id =
entity.sub_type1 ) AS subtype1, " +
"(SELECT type FROM entity_sub_type WHERE id =
entity.sub_type2 ) AS subtype2, " +
"block_address.block_id " +
"FROM entity INNER JOIN " +
"( block_address INNER JOIN street " +
"ON block_address.street_id = street.id) " +
"ON entity.block_address = block_address.id " +
"WHERE street.id = " + streetId;

OleDbCommand cmd = new OleDbCommand( sql, cnn );
cmd.CommandType = CommandType.Text;
cnn.Open();

details.DataSource = cmd.ExecuteReader();
details.DataBind();
cnn.Close();
}

public void onUpdate( Object source, DataGridCommandEventArgs e )
{
string name = ((TextBox)e.Item.Cells[1].Controls[1]).Text;
string addressId = ((DropDownList)(e.Item.FindControl( "ddlNumber"
))).SelectedItem.Value;
string phone1 = ((TextBox)e.Item.Cells[4].Controls[1]).Text;
string phone2 = ((TextBox)e.Item.Cells[5].Controls[1]).Text;
string type = ((DropDownList)(e.Item.FindControl( "ddlType"
))).SelectedItem.Value;
string subType1 = ((DropDownList)(e.Item.FindControl( "ddlSubType1"
))).SelectedItem.Value;
string subType2 = ((DropDownList)(e.Item.FindControl( "ddlSubType2"
))).SelectedItem.Value;

int entityId = e.Item.ItemIndex;
string sql = "UPDATE entity SET " +
"name = '" + name + "', " +
"block_address = " + addressId + ", " +
"phone1 = '" + phone1 + "', " +
"phone2 = '" + phone2 + "', " +
"type = " + type + ", " +
"sub_type1 = " + subType1 + ", " +
"sub_type2 = " + subType2 + " " +
"WHERE id = " + details.DataKeys[entityId];

string connectString =
System.Configuration.ConfigurationSettings.AppSett ings[
"connectString" ];

// Create connection and set connection string
OleDbConnection cnn = new OleDbConnection( connectString );

OleDbCommand cmd = new OleDbCommand( sql, cnn );
cnn.Open();
cmd.ExecuteNonQuery();

details.EditItemIndex = -1;
bindGrid();
}

Thanks,
Kevin

"Teemu Keiski" <jo****@aspalliance.com> wrote in message news:<#i**************@TK2MSFTNGP11.phx.gbl>... Do you rebind the grid *after* update has been done? Post some code.

--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist
"Kevin Pedersen" <ke************@hotmail.com> wrote in message
news:20************************@posting.google.com ...
Hello, I am using an editable datagrid. After I save the changes the
datagrid shows the old values.

I've read the posts about the Page_Load and not binding the datagrid
each time. The SQL that is being sent to the database is correct and
the changes are eventually being made. If I refresh the page after the
update then the new values appear.

I noticed that when I put a breakpoint in my update handler everything
works fine. When I take out the breakpoint, I get the old values. It's
like the update isn't happening fast enough. I'm updating then
selecting before the update is finished. Or am I way off base and I'm
doing something else wrong?

Help.

Thanks in advance,
Kevin

Nov 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Kashif Mehmood | last post by:
Greeting I am using the following code to delete a row from a datagrid ---------------- Private Sub dgClientTypes_DeleteCommand(ByVal source As Object, ByVal e As...
2
by: Jim Bancroft | last post by:
This may be a no-brainer, but I'm sure I follow what's happening here... I have a DataGrid with one DropDownList per row. If I select a few DropDown items and postback my page, I can't loop...
0
by: Luis Esteban Valencia | last post by:
I have a datagrid with no editable fields except checkboxes at the beginning of each row. Is it possible to make certain columns in a row editable if a user selects the checkbox of that row? I...
2
by: P K | last post by:
I am using server.transfer for a website being developed in vs.net 2005 And I need to get the posted values after server.transfer. For this I set the second parameter "true" in the transfer...
6
by: Dugo | last post by:
I'm trying to use a "keypad" form (with command buttons for numbers 0 thru 9) I developed to allow users to first click a textbox on one form, then click a number on the keypad and have the value...
1
by: Michael | last post by:
Hi, I've got a simple web(asp.net) form that adds a record to the database. That works fine, but I also would like to have the datagrid refreshed with the new record. What is the best way to...
2
by: marty | last post by:
I did some searchs, but can't find the answer to my problems. I have a editable DataGrid. I do an update of one of the rows. Postback "OnUpdateCommand" Call Oracle proc to do that actual...
1
by: HenHouse | last post by:
Hi all; I think I've asked this question before but it looks like I'm going to need a deeper understanding of the problem rather than just a quick fix... I have three tables represented by three...
4
by: injanib via AccessMonster.com | last post by:
I have a combo box called "Recipient" who's row source is a table called "Main" with three columns. The three columns are "Name", "Floor", "Location". Following the combo box are two fields called...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.