Welcome to Dream.In.Code
Getting Help is Easy!

Join 131,473 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,822 people online right now. Registration is fast and FREE... Join Now!




order entry page need help with command buttons

 
Reply to this topicStart new topic

order entry page need help with command buttons

johntigner
post 7 Oct, 2008 - 03:21 PM
Post #1


New D.I.C Head

*
Joined: 7 Oct, 2008
Posts: 2

i made an order entry page with two ddl's a gridview, a formview and a listview.. ddl1 is bound to the name fieild in the menu table and selects a restrauant which causes that restrauants menu to appear in the gridview ... ddl2 is bound to the phone number field in the customer table which causes the formview to display current customer info with editing and inserting working except inserting new customer or editing phone number does not postback to ddl2(only reloading the page will display the edited or new phone number)
the listview is bound to the orderdetail table and displays nothing at this time.... the details view which contains the menu info also has four command fields with commandbuttons for ordering small, med, large and xlarge items. i want to use the command buttons to write that item order to the orderdetail table...each item has pricing for available sizes ... only the command button for the correspondind price field should work(ie. if main menu.small price field is the only field that has a price .. then small price button should be the only button to write an item order to the table if all four fields have prices then all four buttons should work.
my hope is that someone could give me some direction on how to make the commandbuttons do their job.


heres all my code sofar

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 nameTextBox = (TextBox)DetailsView1.Rows[1].Cells[1].Controls[0];
            nameTextBox.Text = DropDownList1.SelectedValue;
            nameTextBox.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 johntigner: 7 Oct, 2008 - 03:47 PM
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 11/19/08 11:42PM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month