473,386 Members | 1,793 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

GridView Update not updating data

I have a GridView with a couple of TemplateFields. When I click the update
link the Gridview returns to display mode with no errors but the data from
bound text fields or dropdown list isn't updated in the table. I'm stumped
and any help would be appreciated.

Thanks much.

My GridView:

<asp:GridView ID="VanListGridView" runat="server"
AutoGenerateDeleteButton="True" AutoGenerateEditButton="True"
CellPadding="3" GridLines="Horizontal"
DataSourceID="sdsVans" DataKeyNames="VanId"
AutoGenerateColumns="False" CssClass="waGridView"
AllowPaging="True" ShowFooter="true"
HorizontalAlign="Center">
<FooterStyle CssClass="waFooterStyle" />
<RowStyle CssClass="waRowStyle" />
<EmptyDataTemplate>
<asp:HyperLink ID="HyperLink1" runat="server" CssClass="waLink"
NavigateUrl="VanDetail.aspx">New</asp:HyperLink>
The table is empty.</EmptyDataTemplate>
<SelectedRowStyle CssClass="waSelectedRowStyle" />
<PagerStyle CssClass="waPagerStyle" HorizontalAlign="Right" />
<HeaderStyle CssClass="waHeaderStyle" />
<AlternatingRowStyle CssClass="waAlternatingRowStyle" />
<Columns>
<asp:BoundField DataField="VanId" ReadOnly="true"
HeaderText="Id" SortExpression="VanId" />
<asp:BoundField DataField="VendorVanNo" HeaderText="Vendor
Van#" SortExpression="VendorVanNo" />
<asp:TemplateField HeaderText="VendorCode" ItemStyle-Width="60">
<ItemTemplate>
<asp:literal ID="Literal1" runat="server" Text='<%#
Eval("VendorCode") %>' />
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="ddlVendors" runat="server"
DataSourceID="sdsVendors" DataTextField="VendorCode"
DataValueField="VendorCode" Width="80"
SelectedValue='<%# Bind("VendorCode") %>'>
</asp:DropDownList>
</EditItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Status" HeaderText="Status"
SortExpression="Status">
<ItemStyle Width="100" />
</asp:BoundField>
<asp:TemplateField HeaderText="Active">
<ItemTemplate>
<asp:CheckBox ID="ActiveCheckBox" runat="server"
Checked='<%# Eval("Active") %>' CssClass="waCheckBox" />
</ItemTemplate>
<EditItemTemplate>
<asp:CheckBox ID="ActiveCheckBox" runat="server"
Checked='<%# Bind("Active") %>' CssClass="waCheckBox" />
</EditItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="StartDate" HeaderText="Start"
SortExpression="StartDate"
DataFormatString="{0:d}" HtmlEncode="false" />
<asp:BoundField DataField="EndDate" HeaderText="End"
SortExpression="EndDate" DataFormatString="{0:d}" HtmlEncode="false" />
</Columns>
</asp:GridView>

My Primary Vendors table SQL data source

<asp:SqlDataSource ID="sdsVans" runat="server"
ProviderName="System.Data.SqlClient"
ConnectionString="<%$ ConnectionStrings:myDB %>"
SelectCommand="SELECT VanId, VendorVanNo, VendorCode, StartDate,
EndDate, Status, Active FROM dbo.Vans order by VanId"
UpdateCommand="Update dbo.Vans set VendorVanNo=@VendorVanNo,
VendorCode=@VendorCode, Status=@Status, Active=@Active, StartDate=@StartDate,
EndDate=@EndDate where VanId=@VanId"
DeleteCommand="Delete from dbo.Vans where VanId=@VanId">
</asp:SqlDataSource>

DataSource for dropdownlist:
<asp:SqlDataSource ID="sdsVendors" runat="server"
ProviderName="System.Data.SqlClient"
ConnectionString="<%$ ConnectionStrings:cobbcc %>"
SelectCommand="SELECT VendorCode FROM dbo.Vendors order by VendorCode">
</asp:SqlDataSource>
Mar 22 '06 #1
6 2380
Doesn't look like you have an UpdateCommand set.

David Betz
WinFX Harmonics Blog
http://www.davidbetz.net/winfx/

Mar 22 '06 #2
I am using this update command:
UpdateCommand="Update dbo.Vans set VendorVanNo=@VendorVanNo,
VendorCode=@VendorCode, Status=@Status, Active=@Active, StartDate=@StartDate,
EndDate=@EndDate where VanId=@VanId"

"ag******@gmail.com" wrote:
Doesn't look like you have an UpdateCommand set.

David Betz
WinFX Harmonics Blog
http://www.davidbetz.net/winfx/

Mar 22 '06 #3

The delete method in your code uses the same WHERE condition as the Update.
If the update were not working, I would expect that the Delete would not work
either. Can you verify? If so, try defining an UpdateParameters collection
where you typecast each parameter using the proper "Type" (use the other post
in which I explained to you the use of the UpdateParameters) and try it again.

--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"Dabbler" wrote:
I am using this update command:
UpdateCommand="Update dbo.Vans set VendorVanNo=@VendorVanNo,
VendorCode=@VendorCode, Status=@Status, Active=@Active, StartDate=@StartDate,
EndDate=@EndDate where VanId=@VanId"

"ag******@gmail.com" wrote:
Doesn't look like you have an UpdateCommand set.

David Betz
WinFX Harmonics Blog
http://www.davidbetz.net/winfx/

Mar 23 '06 #4
q
My mistake I misunderstood your question (and read your code wrong!)
What result are you looking for?

David Betz
WinFX Harmonics Blog
http://www.davidbetz.net/winfx/

Mar 23 '06 #5

Thanks for your reply David. I was just lamenting the fact that the
UpdateCommand did nothing. No errors and no update in the table. I have since
gven up on editing with the GridView and instead use the SelectCommand to
redirect to antoher page with a DetailsView for the edit.

Spending too much time trying to fathom the mysteries of binding to
SqlDataSource and not enough time producing results ;)
"q" wrote:
My mistake I misunderstood your question (and read your code wrong!)
What result are you looking for?

David Betz
WinFX Harmonics Blog
http://www.davidbetz.net/winfx/

Mar 23 '06 #6
Yes the DeleteCommand worked.

I have since given up on editing the table with the GridView and instead use
the SelectCommand to redirect to another page with a DetailsView for the edit.

From my posts I'm sure you can see I'm spending too much time trying to
fathom the mysteries of binding to SqlDataSource and not enough time
producing results, probably should have stuck with the old style of coding a
dataset/dataadapter solution as in ASP.NET v1 ;)

Thanks for your ongoing assistance.

"Phillip Williams" wrote:

The delete method in your code uses the same WHERE condition as the Update.
If the update were not working, I would expect that the Delete would not work
either. Can you verify? If so, try defining an UpdateParameters collection
where you typecast each parameter using the proper "Type" (use the other post
in which I explained to you the use of the UpdateParameters) and try it again.

--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"Dabbler" wrote:
I am using this update command:
UpdateCommand="Update dbo.Vans set VendorVanNo=@VendorVanNo,
VendorCode=@VendorCode, Status=@Status, Active=@Active, StartDate=@StartDate,
EndDate=@EndDate where VanId=@VanId"

"ag******@gmail.com" wrote:
Doesn't look like you have an UpdateCommand set.

David Betz
WinFX Harmonics Blog
http://www.davidbetz.net/winfx/

Mar 23 '06 #7

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

Similar topics

3
by: | last post by:
Hello, I have created an ASP.NET 2.0 application that utilized a Gridview Control to display and update/delete data. The problem I am having is that the gridview control is displaying the data...
8
by: Mike Kelly | last post by:
I've chosen to implement the "optimistic concurrency" model in my application. To assist in that, I've added a ROWVERSION (TIMESTAMP) column to my main tables. I read the value of the column in my...
4
by: Nalaka | last post by:
Hi, I have two questions about gridViews. 1. How can I intercept the row/column values at loading to change values? 2. After I update a row (using default update functionality), how can I...
0
by: troyblakely | last post by:
I have a gridview which is pulling data from a SqlDataSource, the select command queries a view and the update command is a stored procedure. I'm using a stored procedure because several tables...
3
by: pblack9455 | last post by:
I have a simple requirement to bind a small ArrayList of (ItemLine) Objects to a GridView control. The Gridview renders on the page and allows me to click update/edit buttons...however the data...
1
by: Japskunk | last post by:
I am having trouble updating a SQL table through the GridView "Auto" Enable Edit Feature... I am connecting to a SQL 2000 Server with a SQLDataSource I have created the Update Query in the Command...
4
by: =?Utf-8?B?QmFyYmFyYSBBbGRlcnRvbg==?= | last post by:
I setup a simple gridview as a utility just to do some updates, nothing fancy just wanted easy UI to make updates. When I select ‘Edit’, I get the fields I want to edit. I edit them and click...
5
by: Luqman | last post by:
I added new rows to the GridView with the following code. I am using SqlDataSource and Sql Server 2000 Northwind Database Customers table. Dim sqlarg As New DataSourceSelectArguments Dim dv...
11
by: SAL | last post by:
Hello, I have a Gridview control (.net 2.0) that I'm having trouble getting the Update button to fire any kind of event or preforming the update. The datatable is based on a join so I don't know...
0
by: BizWeb | last post by:
Hi, i am new to ASP.NET. I have write a very simple code to try the updating of the GridView but it is not updating the data. Below is the simple code that i have use. <%@ Page Language="vb"...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
Oralloy
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,...

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.