By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,384 Members | 714 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,384 IT Pros & Developers. It's quick & easy.

GridView not updating or deleting

P: 1
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
Share this question for a faster answer!
Share on Google+

Post your reply

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