i'm using a ddl to populate a gridview ... in the gridview i use the select field to open a details view so i can edit records or insert new records. when the page loads in the ddl i select a restraunt .. the gridview displays that restraunts menu item .. when i select an item i get the detailsview of that menu item
My problem is with editing and inserting new items ... when i choose either the detailsview changes mode and goes through the motions of editing or inserting , but no data is written to the table
i don't get any errors so theres not stack trace to see.
CODE
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void DetailsView1_ItemInserted(Object sender, System.Web.UI.WebControls.DetailsViewInsertedEventArgs e)
{
if (e.Exception != null)
{
ErrorMessageLabel.Text = "An error occured while entering this record. Please verify you have entered data in the correct format.";
e.ExceptionHandled = true;
}
GridView1.DataBind();
}
protected void DetailsView1_ItemUpdated(Object sender, System.Web.UI.WebControls.DetailsViewUpdatedEventArgs e)
{
GridView1.DataBind();
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
DetailsView1.ChangeMode(DetailsViewMode.ReadOnly);
}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
DetailsView1.ChangeMode(DetailsViewMode.ReadOnly);
}
protected void GridView1_PageIndexChanged(object sender, EventArgs e)
{
DetailsView1.ChangeMode(DetailsViewMode.ReadOnly);
}
protected void GridView1_Sorted(object sender, EventArgs e)
{
DetailsView1.ChangeMode(DetailsViewMode.ReadOnly);
}
protected void GridView1_RowDeleted(object sender, GridViewDeletedEventArgs e)
{
if (e.Exception != null)
{
ErrorMessageLabel.Text = "Failed to DELETE due to foreign key contstraint on the table. You may only delete rows which have no related records.";
e.ExceptionHandled = true;
}
}
protected void DetailsView1_DataBound(object sender, EventArgs e)
{
if (DetailsView1.CurrentMode == DetailsViewMode.Insert)
{
TextBox stateTextBox = (TextBox)DetailsView1.Rows[10].Cells[1].Controls[0];
stateTextBox.Text = DropDownList1.SelectedValue;
stateTextBox.Enabled = false;
}
}
</script>
<html>
<head runat="server">
<title>GridView DetailsView Master-Details (Insert)</title>
<style type="text/css">
.style5 {
font-size: x-large;
color: #FF0000;
}
</style>
</head>
<body>
<form id="form1" runat="server" style="width: 1407px">
<b><span class="style5">MyDelivery Menu Edit Screen</span><br />
<br />
<br />
Choose a Restaurant:<br />
</b>
<table style="width: 100%">
<tr>
<td style="width: 1076px; height: 26px;">
<asp:DropDownList id="DropDownList1" runat="server" AppendDataBoundItems="True" AutoPostBack="True" DataSourceID="SqlDataSource1" DataTextField="name" DataValueField="name">
<asp:listitem>-- Choose a Restraunt --</asp:listitem>
</asp:DropDownList>
</td>
<td style="height: 26px"></td>
</tr>
<tr>
<td style="width: 1076px">
<asp:GridView id="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False" DataKeyNames="item_number" DataSourceID="SqlDataSource2" Height="101px" OnPageIndexChanged="GridView1_PageIndexChanged" OnRowDeleted="GridView1_RowDeleted" OnSelectedIndexChanged="GridView1_SelectedIndexChanged" OnSorted="GridView1_Sorted" PageSize="5" SelectedIndex="0" Width="77px">
<Columns>
<asp:commandfield ShowSelectButton="True">
</asp:commandfield>
<asp:boundfield DataField="name" HeaderText="name" SortExpression="name" ShowHeader="False" Visible="False">
</asp:boundfield>
<asp:boundfield DataField="menu_catagory" HeaderText="menu_catagory" SortExpression="menu_catagory">
</asp:boundfield>
<asp:boundfield DataField="item_number" HeaderText="item_number" InsertVisible="False" ReadOnly="True" SortExpression="item_number">
</asp:boundfield>
<asp:boundfield DataField="menu_number" HeaderText="menu_number" SortExpression="menu_number">
</asp:boundfield>
<asp:boundfield DataField="catagory_items" HeaderText="catagory_items" SortExpression="catagory_items">
</asp:boundfield>
<asp:boundfield DataField="item_description" HeaderText="item_description" SortExpression="item_description">
</asp:boundfield>
<asp:boundfield DataField="add_items_code" HeaderText="add_items_code" SortExpression="add_items_code">
</asp:boundfield>
<asp:boundfield DataField="small_price" HeaderText="small_price" SortExpression="small_price">
</asp:boundfield>
<asp:boundfield DataField="med_price" HeaderText="med_price" SortExpression="med_price">
</asp:boundfield>
<asp:boundfield DataField="large_price" HeaderText="large_price" SortExpression="large_price">
</asp:boundfield>
<asp:boundfield DataField="xlarge_price" HeaderText="xlarge_price" SortExpression="xlarge_price">
</asp:boundfield>
</Columns>
<SelectedRowStyle BackColor="Silver" Font-Bold="True" ForeColor="Black" />
</asp:GridView>
</td>
<td>
<asp:DetailsView AutoGenerateRows="False" DataSourceID="SqlDataSource3"
HeaderText="Item Details" ID="DetailsView1" runat="server" Width="338px" OnItemUpdated="DetailsView1_ItemUpdated"
OnItemInserted="DetailsView1_ItemInserted" OnDataBound="DetailsView1_DataBound" DefaultMode="Insert" DataKeyNames="name,menu_number">
<Fields>
<asp:boundfield DataField="name" HeaderText="name" SortExpression="name">
</asp:boundfield>
<asp:boundfield DataField="menu_catagory" HeaderText="menu_catagory" SortExpression="menu_catagory">
</asp:boundfield>
<asp:boundfield DataField="item_number" HeaderText="item_number" ReadOnly="True" SortExpression="item_number">
</asp:boundfield>
<asp:boundfield DataField="menu_number" HeaderText="menu_number" SortExpression="menu_number">
</asp:boundfield>
<asp:boundfield DataField="catagory_items" HeaderText="catagory_items" SortExpression="catagory_items">
</asp:boundfield>
<asp:boundfield DataField="item_description" HeaderText="item_description" SortExpression="item_description">
</asp:boundfield>
<asp:boundfield DataField="add_items_code" HeaderText="add_items_code" SortExpression="add_items_code">
</asp:boundfield>
<asp:boundfield DataField="small_price" HeaderText="small_price" SortExpression="small_price">
</asp:boundfield>
<asp:boundfield DataField="med_price" HeaderText="med_price" SortExpression="med_price">
</asp:boundfield>
<asp:boundfield DataField="large_price" HeaderText="large_price" SortExpression="large_price">
</asp:boundfield>
<asp:boundfield DataField="xlarge_price" HeaderText="xlarge_price" SortExpression="xlarge_price">
</asp:boundfield>
<asp:CommandField ShowEditButton="True" ShowInsertButton="True" />
</Fields>
</asp:DetailsView>
</td>
</tr>
</table>
<br />
<br />
<br />
<table>
<tr>
<td valign="top"> </td>
<td valign="top">
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:mydeliveryConnectionString1 %>"
DeleteCommand="DELETE FROM [main menu] WHERE [item number] = @item_number"
InsertCommand="INSERT INTO [main menu] ([name], [menu catagory], [menu number], [catagory items], [item description], [add items code], [small price], [med price], [large price], [xlarge price]) VALUES (@name, @menu_catagory, @menu_number, @catagory_items, @item_description, @add_items_code, @small_price, @med_price, @large_price, @xlarge_price)"
SelectCommand="SELECT [name], [menu catagory] AS menu_catagory, [item number] AS item_number, [menu number] AS menu_number, [catagory items] AS catagory_items, [item description] AS item_description, [add items code] AS add_items_code, [small price] AS small_price, [med price] AS med_price, [large price] AS large_price, [xlarge price] AS xlarge_price FROM [main menu] WHERE ([name] = @name) ORDER BY [item number]" UpdateCommand="UPDATE [main menu] SET [name] = @name, [menu catagory] = @menu_catagory, [menu number] = @menu_number, [catagory items] = @catagory_items, [item description] = @item_description, [add items code] = @add_items_code, [small price] = @small_price, [med price] = @med_price, [large price] = @large_price, [xlarge price] = @xlarge_price WHERE [item number] = @item_number">
<SelectParameters>
<asp:controlparameter ControlID="DropDownList1" Name="name" PropertyName="SelectedValue" Type="String" />
</SelectParameters>
<DeleteParameters>
<asp:parameter Name="item_number" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asp:parameter Name="name" Type="String" />
<asp:parameter Name="menu_catagory" Type="String" />
<asp:parameter Name="menu_number" Type="Int32" />
<asp:parameter Name="catagory_items" Type="String" />
<asp:parameter Name="item_description" Type="String" />
<asp:parameter Name="add_items_code" Type="String" />
<asp:parameter Name="small_price" Type="Decimal" />
<asp:parameter Name="med_price" Type="Decimal" />
<asp:parameter Name="large_price" Type="Decimal" />
<asp:parameter Name="xlarge_price" Type="Decimal" />
<asp:parameter Name="item_number" Type="Int32" />
</UpdateParameters>
<InsertParameters>
<asp:parameter Name="name" Type="String" />
<asp:parameter Name="menu_catagory" Type="String" />
<asp:parameter Name="menu_number" Type="Int32" />
<asp:parameter Name="catagory_items" Type="String" />
<asp:parameter Name="item_description" Type="String" />
<asp:parameter Name="add_items_code" Type="String" />
<asp:parameter Name="small_price" Type="Decimal" />
<asp:parameter Name="med_price" Type="Decimal" />
<asp:parameter Name="large_price" Type="Decimal" />
<asp:parameter Name="xlarge_price" Type="Decimal" />
</InsertParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:mydeliveryConnectionString1 %>" SelectCommand="SELECT DISTINCT [name] FROM [main menu]">
</asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:mydeliveryConnectionString1 %>"
DeleteCommand="DELETE FROM [main menu] WHERE [item number] = @item_number"
InsertCommand="INSERT INTO [main menu] ([name], [menu catagory], [menu number], [catagory items], [item description], [add items code], [small price], [med price], [large price], [xlarge price]) VALUES (@name, @menu_catagory, @menu_number, @catagory_items, @item_description, @add_items_code, @small_price, @med_price, @large_price, @xlarge_price)"
SelectCommand="SELECT [name], [menu catagory] AS menu_catagory, [item number] AS item_number, [menu number] AS menu_number, [catagory items] AS catagory_items, [item description] AS item_description, [add items code] AS add_items_code, [small price] AS small_price, [med price] AS med_price, [large price] AS large_price, [xlarge price] AS xlarge_price FROM [main menu] WHERE ([item number] = @item_number)"
UpdateCommand="UPDATE [main menu] SET [name] = @name, [menu catagory] = @menu_catagory, [menu number] = @menu_number, [catagory items] = @catagory_items, [item description] = @item_description, [add items code] = @add_items_code, [small price] = @small_price, [med price] = @med_price, [large price] = @large_price, [xlarge price] = @xlarge_price WHERE [item number] = @item_number">
<SelectParameters>
<asp:controlparameter ControlID="GridView1" Name="item_number" PropertyName="SelectedValue" Type="Int32" />
</SelectParameters>
<DeleteParameters>
<asp:parameter Name="item_number" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asp:parameter Name="name" Type="String" />
<asp:parameter Name="menu_catagory" Type="String" />
<asp:parameter Name="menu_number" Type="Int32" />
<asp:parameter Name="catagory_items" Type="String" />
<asp:parameter Name="item_description" Type="String" />
<asp:parameter Name="add_items_code" Type="String" />
<asp:parameter Name="small_price" Type="Decimal" />
<asp:parameter Name="med_price" Type="Decimal" />
<asp:parameter Name="large_price" Type="Decimal" />
<asp:parameter Name="xlarge_price" Type="Decimal" />
<asp:parameter Name="item_number" Type="Int32" />
</UpdateParameters>
<InsertParameters>
<asp:parameter Name="name" Type="String" />
<asp:parameter Name="menu_catagory" Type="String" />
<asp:parameter Name="menu_number" Type="Int32" />
<asp:parameter Name="catagory_items" Type="String" />
<asp:parameter Name="item_description" Type="String" />
<asp:parameter Name="add_items_code" Type="String" />
<asp:parameter Name="small_price" Type="Decimal" />
<asp:parameter Name="med_price" Type="Decimal" />
<asp:parameter Name="large_price" Type="Decimal" />
<asp:parameter Name="xlarge_price" Type="Decimal" />
</InsertParameters>
</asp:SqlDataSource>
</td>
</tr>
</table>
<br />
<asp:Label id="ErrorMessageLabel" runat="server" enableviewstate="false" />
</form>
</body>
</html>
This post has been edited by jayman9: 7 Oct, 2008 - 07:41 AM