473,804 Members | 2,719 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

GridView not updating or deleting

1 New Member
I'm making a quick CD catalog to help me learn ASP.NET (using C# primarily.) I have a number of gridview's on my site that are working properly, but for some reason, one is not updating or deleting. I have the buttons for both visible, and when I click edit, the update fields show up properly, but once I click 'update' the table is back with it's old information. When I click 'delete' the page completes the postback properly, but once again, the information is the same.

Here is my source code for the page in question:
Expand|Select|Wrap|Line Numbers
  1. <asp:GridView ID="FullEditAlbumGridView" runat="server" AllowPaging="True" AllowSorting="True"
  2.         AutoGenerateColumns="False" DataSourceID="FullEditSqlDataSource" Width="717px" AutoGenerateDeleteButton="True" AutoGenerateEditButton="True">
  3.         <FooterStyle BackColor="DarkGreen" BorderColor="Ivory" BorderStyle="Solid" ForeColor="Ivory" />
  4.         <Columns>
  5.             <asp:BoundField DataField="AlbumID" HeaderText="AlbumID" InsertVisible="False" ReadOnly="True"
  6.                 ShowHeader="False" SortExpression="AlbumID" Visible="False" />
  7.             <asp:TemplateField HeaderText="AlbumTitle" SortExpression="AlbumTitle">
  8.                 <EditItemTemplate>
  9.                     <asp:TextBox ID="TitleTextBox" runat="server" Text='<%# Bind("AlbumTitle") %>'></asp:TextBox>
  10.                     <asp:RequiredFieldValidator ID="AlbumTitleValidator" runat="server" ErrorMessage="<br />Title is required" ControlToValidate="TitleTextBox" Display="Dynamic"></asp:RequiredFieldValidator>
  11.                 </EditItemTemplate>
  12.                 <ItemTemplate>
  13.                     <asp:Label ID="TitleLabel" runat="server" Text='<%# Bind("AlbumTitle") %>'></asp:Label>
  14.                 </ItemTemplate>
  15.             </asp:TemplateField>
  16.             <asp:TemplateField HeaderText="AlbumYear" SortExpression="AlbumYear">
  17.                 <EditItemTemplate>
  18.                     <asp:TextBox ID="YearPubTextBox" Type="Integer" runat="server" Text='<%# Bind("AlbumYear") %>'></asp:TextBox>
  19.                     <asp:RequiredFieldValidator ID="YearValidator" runat="server" ControlToValidate="YearPubTextBox" Display="Dynamic" ErrorMessage="<br />Year is a required field"></asp:RequiredFieldValidator>
  20.  
  21.                 </EditItemTemplate>
  22.                 <ItemTemplate>
  23.                     <asp:Label ID="YearPubLabel" runat="server" Text='<%# Bind("AlbumYear") %>'></asp:Label>
  24.                 </ItemTemplate>
  25.             </asp:TemplateField>
  26.             <asp:TemplateField HeaderText="GenreName" SortExpression="GenreName">
  27.                <EditItemTemplate>
  28.                     <asp:DropDownList ID="GenreList" runat="server" DataSourceID="GenreSqlDataSource" DataTextField="GenreName"
  29.                         DataValueField="GenreID" SelectedValue='<%# Bind("AlbumGenreID") %>'>
  30.                     </asp:DropDownList><asp:SqlDataSource ID="GenreSqlDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:MyCdsConnectionString %>"
  31.                         SelectCommand="SELECT * FROM [Genre] ORDER BY [GenreName]"></asp:SqlDataSource>
  32.                 </EditItemTemplate>                <ItemTemplate>
  33.                     <asp:Label ID="GenreLabel" runat="server" Text='<%# Bind("GenreName") %>'></asp:Label>
  34.                 </ItemTemplate>
  35.             </asp:TemplateField>
  36.             <asp:TemplateField HeaderText="BandName" SortExpression="BandName">
  37.                 <EditItemTemplate>
  38.                     <asp:DropDownList ID="BandNameList" runat="server" DataSourceID="BandSqlDataSource" DataTextField="BandName"
  39.                         DataValueField="BandID" SelectedValue='<%# Bind("AlbumBandID") %>'>
  40.                     </asp:DropDownList><asp:SqlDataSource ID="BandSqlDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:MyCdsConnectionString %>"
  41.                         SelectCommand="SELECT * FROM [Band] ORDER BY [BandName]"></asp:SqlDataSource>
  42.                 </EditItemTemplate>
  43.                 <ItemTemplate>
  44.                     <asp:Label ID="BandNameLabel" runat="server" Text='<%# Bind("BandName") %>'></asp:Label>
  45.                 </ItemTemplate>
  46.             </asp:TemplateField>
  47.         </Columns>
  48.         <RowStyle BackColor="Beige" BorderColor="Ivory" BorderStyle="Solid" ForeColor="DarkGreen" />
  49.         <PagerStyle BackColor="DarkGreen" BorderColor="Ivory" BorderStyle="Solid" ForeColor="Ivory" />
  50.         <HeaderStyle BackColor="DarkGreen" BorderColor="Ivory" BorderStyle="Solid" BorderWidth="1px"
  51.             ForeColor="Ivory" />
  52.         <AlternatingRowStyle BackColor="Transparent" BorderColor="Ivory" ForeColor="DarkGreen" />
  53.     </asp:GridView>
  54.     <br />
  55.     <asp:HyperLink ID="LoginLink" runat="server" NavigateUrl="~/Admin/Default.aspx">Log In</asp:HyperLink><br />
  56.     <br />
  57.     <asp:SqlDataSource ID="FullEditSqlDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:MyCdsConnectionString %>"
  58.         DeleteCommand="DELETE FROM [Album] WHERE [AlbumID] = @AlbumID"
  59.         InsertCommand="INSERT INTO [Album] ([AlbumTitle], [AlbumYear], [AlbumGenreID], [AlbumBandID]) VALUES (@AlbumTitle, @AlbumYear, @AlbumGenreID, @AlbumBandID)"
  60.         SelectCommand="SELECT Album.*, Genre.GenreName, Band.BandName FROM Album INNER JOIN Band ON Album.AlbumBandID = Band.BandID INNER JOIN Genre ON Album.AlbumGenreID = Genre.GenreID"
  61.         UpdateCommand="UPDATE Album SET AlbumTitle = @AlbumTitle, AlbumYear = @AlbumYear, AlbumGenreID = @AlbumGenreID, AlbumBandID = @AlbumBandID WHERE (AlbumID = @AlbumID)">
  62.         <DeleteParameters>
  63.             <asp:Parameter Name="AlbumID" />
  64.         </DeleteParameters>
  65.         <UpdateParameters>
  66.             <asp:Parameter Name="AlbumTitle" />
  67.             <asp:Parameter Name="AlbumYear" />
  68.             <asp:Parameter Name="AlbumGenreID" />
  69.             <asp:Parameter Name="AlbumBandID" />
  70.             <asp:Parameter Name="AlbumID" />
  71.         </UpdateParameters>
  72.         <InsertParameters>
  73.             <asp:Parameter Name="AlbumTitle" />
  74.             <asp:Parameter Name="AlbumYear" />
  75.             <asp:Parameter Name="AlbumGenreID" />
  76.             <asp:Parameter Name="AlbumBandID" />
  77.         </InsertParameters>
  78.     </asp:SqlDataSource>
  79.     <asp:SqlDataSource ID="GenreSqlDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:MyCdsConnectionString %>"
  80.         SelectCommand="SELECT [GenreName], [GenreID] FROM [Genre]ORDER BY [GenreName]"></asp:SqlDataSource>
  81.     <asp:SqlDataSource ID="BandSqlDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:MyCdsConnectionString %>"
  82.         SelectCommand="SELECT [BandID], [BandName] FROM [Band] ORDER BY [BandName]"></asp:SqlDataSource>
  83.  
  84.     &nbsp;<br />  
  85.  
Oct 9 '07 #1
0 1556

Sign in to post your reply or Sign up for a free account.

Similar topics

3
6339
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 correctly but it is not updating or deleting the rows. What I did was, in design view, added a gridview control and added an sqldatasource control. I configured the data source to update and delete. In the gridview tasks I selected enable...
3
2236
by: adam222 | last post by:
hello, i have a web-form with a GridView control, i wanted to update & delete, using the AutoGenerateEditButton. when i used it with sqlDataSource (executing SP in the DB) it works like a charm, but when i want to pass the data through the application's layers (BL etc.), it did not work. it seems that the 'AutoGenerateEditButton' is capable only with sqlDataSource...
5
15345
by: Brian McClellan | last post by:
Just wondering if anyone has a simple example of creating a gridview completely programmatically, i'm not doing anything terribly sophisticated. When creating the gridview declaratively evertying works fine, however programmatically, while the grid will display data that exsists in the database, any operation on the data ( editing/updating/deleting ) seems to cause a rowdeleting/updating etc error. Or is this simply not meant to be done?
5
2250
by: Michael | last post by:
Hi Everyone, I've been having a problem with the Gridview control. I have posted a few messages relating to the issues, but I have a general question. Does the Dataview control have to be bound to a datasource that also contains the update/delete Sql statements? The resaon I ask is that I've done just about all I can do and can't update the grid. In the RowUpdating event I'm getting no values in the newvalues or oldvalues vars. I do bind a...
1
2301
by: pblack9455 | last post by:
Is it possible to do the following:- Create an ObjectDataSource object that has an embedded ArrayList of Objects. Allow the ASP.NET application to create and populate an instance of the ObjectDataSource...and pass this to a GridView control... I don't want the GridView control to create its own instance of the ObjectDataSource object.?? this could be where the problem is... For example I have
8
18095
by: Greg Lyles | last post by:
Hi all, I'm trying to develop an ASP.NET 2.0 website and am running into some real problems with what I thought would be a relatively simple thing to do. In a nutshell, I'm stuck on trying to display data in a "GridView" which is tied to an "ObjectDataSource". In turn, this ObjectDatasource gets it's data from a strongly-typed business object within my code.
4
8764
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 ‘Update’, the page returns to its original state (prior to clicking Edit) and no updates occur in the DB. What am I missing? I included the html code below. -- Thank-you, Barbara Alderton <body>
2
5343
by: Michael | last post by:
It seems that a gridview allows us to delete only a single row at a time. How to extend this functionality to select multiple rows and delete all of the selected rows in a single stroke? just like what hotmail web UI is doing now (having the option of selecting multiple rows (using the checkbox provided) and perform a set of operations on them)
2
1638
by: =?Utf-8?B?VGltIFRhZmZsaW5nZXI=?= | last post by:
I've created a DAL and can use the methods to load and manipulate data in a gridview when it is bound to an objectdatasource. But I've been told with a DAL I don't need an objectdatasource at all but I'm having difficulty figuring out how to do it. Loading the data in the gridview is no problem, it's the updating and deleting that won't work. When I click on the Edit or Delete buttons I get an unhandled event error so apparently I need...
0
9706
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, 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...
0
9577
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,...
0
10569
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, 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...
1
10315
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,...
0
10075
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9140
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7615
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6847
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
3
2990
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.