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 3 4932
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.googl e.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
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.BeginEdi t()
2) Change the values in the DataRow
3) Call DataRow.EndEdit ()
4) Connect to the database
5) Call DataAdapter.Upd ate(DataTable)
6) Call DataTable.Accep tChanges()
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)
Here's the code. At least the stuff I thought was relevant.
<asp:datagrid id="details" runat="server"
visible="False"
datakeyfield="e ntity_id"
autogeneratecol umns="False"
headerstyle-font-bold="True"
font-size="10pt"
font-name="Verdana"
oneditcommand=" onEdit"
oncancelcommand ="onCancel"
onupdatecommand ="onUpdate"
<columns>
<asp:boundcolum n headertext="ID" datafield="enti ty_id"
readonly="True" />
<asp:templateco lumn headertext="Nam e">
<itemtemplate >
<asp:label runat="server" id="lblName"
text='<%# DataBinder.Eval ( Container.DataI tem, "entity_nam e"
) %>' />
</itemtemplate>
<edititemtempla te>
<asp:textbox id="txtName" runat="server" font-name="Verdana"
text='<%# DataBinder.Eval ( Container.DataI tem, "entity_nam e"
) %>' />
</edititemtemplat e>
</asp:templatecol umn>
<asp:templateco lumn headertext="Num ber">
<itemtemplate >
<asp:label id="lblNumber" runat="server"
text='<%# DataBinder.Eval ( Container.DataI tem,
"street_num ber" ) %>' />
</itemtemplate>
<edititemtempla te>
<asp:dropdownli st id="ddlNumber" runat="server"
datasource='<%# getStreetNumber s() %>'
datatextfield=" street_number"
datavaluefield= "id"
onprerender="se tItemIndex" />
</edititemtemplat e>
</asp:templatecol umn>
<asp:templateco lumn runat="server" headertext="Str eet">
<itemtemplate >
<asp:label runat="server" text='<%#
DataBinder.Eval ( Container.DataI tem, "street_nam e" ) + " "
+
DataBinder.Eval ( Container.DataI tem, "street_typ e" ) %>' />
</itemtemplate>
</asp:templatecol umn>
<asp:templateco lumn runat="server" headertext="Pho ne 1">
<itemtemplate >
<asp:label id="lblPhone1" runat="server"
text='<%# DataBinder.Eval ( Container.DataI tem, "phone1" )
%>' />
</itemtemplate>
<edititemtempla te>
<asp:textbox id="txtPhone1" runat="server"
text='<%# DataBinder.Eval ( Container.DataI tem, "phone1" )
%>'
width="80" />
</edititemtemplat e>
</asp:templatecol umn>
<asp:templateco lumn runat="server" headertext="Pho ne 2">
<itemtemplate >
<asp:label id="lblPhone2" runat="server"
text='<%# DataBinder.Eval ( Container.DataI tem, "phone2" )
%>' />
</itemtemplate>
<edititemtempla te>
<asp:textbox id="txtPhone2" runat="server"
text='<%# DataBinder.Eval ( Container.DataI tem, "phone2" )
%>'
width="80" />
</edititemtemplat e>
</asp:templatecol umn>
<asp:templateco lumn runat="server" headertext="Typ e">
<itemtemplate >
<asp:label id="lblType" runat="server"
text='<%# DataBinder.Eval ( Container.DataI tem, "type" ) %>'
/>
</itemtemplate>
<edititemtempla te>
<asp:dropdownli st id="ddlType" runat="server"
datasource='<%# getTypes() %>'
datatextfield=" type"
datavaluefield= "id"
onprerender="se tItemIndex"
/>
</edititemtemplat e>
</asp:templatecol umn>
<asp:templateco lumn runat="server" headertext="Sub Type 1">
<itemtemplate >
<asp:label id="lblSubType1 " runat="server"
text='<%# DataBinder.Eval ( Container.DataI tem, "subtype1" )
%>' />
</itemtemplate>
<edititemtempla te>
<asp:dropdownli st id="ddlSubType1 " runat="server"
datasource='<%# getSubTypes() %>'
datatextfield=" type"
datavaluefield= "id"
onprerender="se tItemIndex"
/>
</edititemtemplat e>
</asp:templatecol umn>
<asp:templateco lumn runat="server" headertext="Sub Type 2">
<itemtemplate >
<asp:label id="lblSubType2 " runat="server"
text='<%# DataBinder.Eval ( Container.DataI tem, "subtype2" )
%>' />
</itemtemplate>
<edititemtempla te>
<asp:dropdownli st id="ddlSubType2 " runat="server"
datasource='<%# getSubTypes() %>'
datatextfield=" type"
datavaluefield= "id"
onprerender="se tItemIndex"
/>
</edititemtemplat e>
</asp:templatecol umn>
<asp:editcomman dcolumn
edittext="Edit"
canceltext="Can cel"
updatetext="Sav e" />
<asp:buttoncolu mn
buttontype="Lin kButton"
commandname="De lete"
text="Delete" />
</columns>
</asp:datagrid>
private void Page_Load(objec t sender, System.EventArg s 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.sele ctedItemValue == "" ? "1" :
streetList.sele ctedItemValue;
// Show results
details.Visible = true;
street_image.Vi sible = true;
}
}
private void bindGrid()
{
string connectString =
System.Configur ation.Configura tionSettings.Ap pSettings[
"connectStr ing" ];
// 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_i d,
block_address.s treet_number, street.name AS street_name, " +
"street.typ e 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_type 1 ) AS subtype1, " +
"(SELECT type FROM entity_sub_type WHERE id =
entity.sub_type 2 ) AS subtype2, " +
"block_address. block_id " +
"FROM entity INNER JOIN " +
"( block_address INNER JOIN street " +
"ON block_address.s treet_id = street.id) " +
"ON entity.block_ad dress = block_address.i d " +
"WHERE street.id = " + streetId;
OleDbCommand cmd = new OleDbCommand( sql, cnn );
cmd.CommandType = CommandType.Tex t;
cnn.Open();
details.DataSou rce = cmd.ExecuteRead er();
details.DataBin d();
cnn.Close();
}
public void onUpdate( Object source, DataGridCommand EventArgs e )
{
string name = ((TextBox)e.Ite m.Cells[1].Controls[1]).Text;
string addressId = ((DropDownList) (e.Item.FindCon trol( "ddlNumber"
))).SelectedIte m.Value;
string phone1 = ((TextBox)e.Ite m.Cells[4].Controls[1]).Text;
string phone2 = ((TextBox)e.Ite m.Cells[5].Controls[1]).Text;
string type = ((DropDownList) (e.Item.FindCon trol( "ddlType"
))).SelectedIte m.Value;
string subType1 = ((DropDownList) (e.Item.FindCon trol( "ddlSubType 1"
))).SelectedIte m.Value;
string subType2 = ((DropDownList) (e.Item.FindCon trol( "ddlSubType 2"
))).SelectedIte m.Value;
int entityId = e.Item.ItemInde x;
string sql = "UPDATE entity SET " +
"name = '" + name + "', " +
"block_addr ess = " + addressId + ", " +
"phone1 = '" + phone1 + "', " +
"phone2 = '" + phone2 + "', " +
"type = " + type + ", " +
"sub_type1 = " + subType1 + ", " +
"sub_type2 = " + subType2 + " " +
"WHERE id = " + details.DataKey s[entityId];
string connectString =
System.Configur ation.Configura tionSettings.Ap pSettings[
"connectStr ing" ];
// Create connection and set connection string
OleDbConnection cnn = new OleDbConnection ( connectString );
OleDbCommand cmd = new OleDbCommand( sql, cnn );
cnn.Open();
cmd.ExecuteNonQ uery();
details.EditIte mIndex = -1;
bindGrid();
}
Thanks,
Kevin
"Teemu Keiski" <jo****@aspalli ance.com> wrote in message news:<#i******* *******@TK2MSFT NGP11.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.googl e.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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 System.Web.UI.WebControls.DataGridCommandEventArgs) Handles dgClientTypes.DeleteComman
cmdClientTypes.CommandText = "Delete from tbClientTypes where (ClientTypeID = @ClientTypeID)
cmdClientTypes.Parameters.Add("@ClientTypeID", SqlDbType.SmallInt...
|
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 through the DataGridItems unless I
rebind my DataGrid. By "can't loop," I mean it's a mighty quick run
through-- zero iterations.
I was wondering...do I have to rebind on postbacks? If so, what happens if
I bind the DataGrid to a different set of...
|
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 want to allow the user to select
multiple rows to make them editable then click an 'update' button at the end
to update the database.
--
LUIS ESTEBAN VALENCIA
MICROSOFT DCE 3.
MIEMBRO ACTIVO DE ALIANZADEV
|
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 method. Also enableViewStateMac
is made false in the destination page. Still I cannot get some changed values.
The scenario is such -
1. I have page 1 with a hidden variable named,"myHid" whose value is set to
"Text1"
2. When a submit happens on...
|
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 entered in
the textbox. It's all seemingly working except that I have an
AfterUpdate event set for the textboxes and that event is NOT triggered
when I use the keypad to enter data. If I enter numbers with the
regular keyboard, the even is...
| |
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 handle this. I have a sqlDatasource as the
datasource for the grid. Thanks for any info.
Michael
|
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 update, which in turn creates a new
row (effective dating).
Call BindGrid which retrieves the rows and binds the data to the grid
again.
|
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 forms, and I need some of the controls to be linked to one another. (some are drop-down boxes, some are Yes/No). I can't use the Control Source property to link them because they each have to save their values independently.
The way I'm currently...
|
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 "Floor" and "Location". The
after update event of the combo box runs the following lines to update the
next two fields.
= Recipient.Column(2)
= Recipient.Column(3)
The combo box is not limited to the values in its rowsource table. What I
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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 we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |