GridView Update not updating data

G

Guest

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>
 
G

Guest

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"
 
G

Guest

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

Guest

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 ;)
 
G

Guest

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.
 

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

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top