locked
Pass value of form text box into column of List View RRS feed

  • Question

  • User-1016229741 posted

    this below script performs the way i want it to and is working fine except for one thing. i am wanting the value that is in a text box (txtOrderID) to pass into a column of the List View which is named OrderID. primary key of one table to foreign key of the detail table back-end SQL. (Orders to OrdersDetail). anyhow it seems like this should be a simple thing to do but i have struggled immensely to the point of moving project to MVC and then moving back because of issues i couldn't resolve. any help on this would be beyond appreciated. thanks.

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ListViewTest.aspx.cs" Inherits="ABCFieldTicketWebApp.ListViewTest" %>

    <!DOCTYPE html>

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
    <title></title>
    </head>
    <body>
    <form id="form1" runat="server">
    <div>
    <asp:Label ID="lblOrderNo" Text="Order No" runat="server"></asp:Label>
    <asp:TextBox ID="txtOrderNo" runat="server"></asp:TextBox>
    <asp:Label ID="lblOrderID" Text="Order ID" runat="server"></asp:Label>
    <asp:TextBox ID="txtOrderID" runat="server"></asp:TextBox>
    <br />
    <asp:Button ID="btnSubmit" runat="server" onclick="btnSubmit_Click" Height="24px" Text="Submit" style="font-family: 'Arial Narrow'; font-size: 12pt; background-color: #CCCCCC;" />
    <br />
    <asp:ListView ID="ListView1" runat="server" DataSourceID="SqlDataSource1" DataKeyNames="OrderItemsId" InsertItemPosition="LastItem">
    <AlternatingItemTemplate>
    <tr style="">
    <td>
    <asp:Button ID="DeleteButton" runat="server" CommandName="Delete" Text="Delete" />
    <asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" />
    </td>
    <td>
    <asp:Label ID="ItemNameLabel" runat="server" Text='<%# Eval("ItemName") %>' />
    </td>
    <td>
    <asp:Label ID="QuantityLabel" runat="server" Text='<%# Eval("Quantity") %>' />
    </td>
    <td>
    <asp:Label ID="RateLabel" runat="server" Text='<%# Eval("Rate") %>' />
    </td>
    <td>
    <asp:Label ID="TotalAmountLabel" runat="server" Text='<%# Eval("TotalAmount") %>' />
    </td>
    <td>
    <asp:Label ID="OrderIDLabel" runat="server" Text='<%# Eval("OrderID") %>' />
    </td>
    <td>
    <asp:Label ID="OrderItemsIdLabel" runat="server" Text='<%# Eval("OrderItemsId") %>' />
    </td>
    </tr>
    </AlternatingItemTemplate>
    <EditItemTemplate>
    <tr style="">
    <td>
    <asp:Button ID="UpdateButton" runat="server" CommandName="Update" Text="Update" />
    <asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="Cancel" />
    </td>
    <td>
    <asp:TextBox ID="ItemNameTextBox" runat="server" Text='<%# Bind("ItemName") %>' />
    </td>
    <td>
    <asp:TextBox ID="QuantityTextBox" runat="server" Text='<%# Bind("Quantity") %>' />
    </td>
    <td>
    <asp:TextBox ID="RateTextBox" runat="server" Text='<%# Bind("Rate") %>' />
    </td>
    <td>
    <asp:TextBox ID="TotalAmountTextBox" runat="server" Text='<%# Bind("TotalAmount") %>' />
    </td>
    <td>
    <asp:TextBox ID="OrderIDTextBox" runat="server" Text='<%# Bind("OrderID") %>' />
    </td>
    <td>
    <asp:Label ID="OrderItemsIdLabel1" runat="server" Text='<%# Eval("OrderItemsId") %>' />
    </td>
    </tr>
    </EditItemTemplate>
    <EmptyDataTemplate>
    <table runat="server" style="">
    <tr>
    <td>No data was returned.</td>
    </tr>
    </table>
    </EmptyDataTemplate>
    <InsertItemTemplate>
    <tr style="">
    <td>
    <asp:Button ID="InsertButton" runat="server" CommandName="Insert" Text="Insert" />
    <asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="Clear" />
    </td>
    <td>
    <asp:TextBox ID="ItemNameTextBox" runat="server" Text='<%# Bind("ItemName") %>' />
    </td>
    <td>
    <asp:TextBox ID="QuantityTextBox" runat="server" Text='<%# Bind("Quantity") %>' />
    </td>
    <td>
    <asp:TextBox ID="RateTextBox" runat="server" Text='<%# Bind("Rate") %>' />
    </td>
    <td>
    <asp:TextBox ID="TotalAmountTextBox" runat="server" Text='<%# Bind("TotalAmount") %>' />
    </td>
    <td>
    <asp:TextBox ID="OrderIDTextBox" runat="server" Text='<%# Bind("OrderID") %>' />
    </td>
    <td>&nbsp;</td>
    </tr>
    </InsertItemTemplate>
    <ItemTemplate>
    <tr style="">
    <td>
    <asp:Button ID="DeleteButton" runat="server" CommandName="Delete" Text="Delete" />
    <asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" />
    </td>
    <td>
    <asp:Label ID="ItemNameLabel" runat="server" Text='<%# Eval("ItemName") %>' />
    </td>
    <td>
    <asp:Label ID="QuantityLabel" runat="server" Text='<%# Eval("Quantity") %>' />
    </td>
    <td>
    <asp:Label ID="RateLabel" runat="server" Text='<%# Eval("Rate") %>' />
    </td>
    <td>
    <asp:Label ID="TotalAmountLabel" runat="server" Text='<%# Eval("TotalAmount") %>' />
    </td>
    <td>
    <asp:Label ID="OrderIDLabel" runat="server" Text='<%# Eval("OrderID") %>' />
    </td>
    <td>
    <asp:Label ID="OrderItemsIdLabel" runat="server" Text='<%# Eval("OrderItemsId") %>' />
    </td>
    </tr>
    </ItemTemplate>
    <LayoutTemplate>
    <table runat="server">
    <tr runat="server">
    <td runat="server">
    <table id="itemPlaceholderContainer" runat="server" border="0" style="">
    <tr runat="server" style="">
    <th runat="server"></th>
    <th runat="server">ItemName</th>
    <th runat="server">Quantity</th>
    <th runat="server">Rate</th>
    <th runat="server">TotalAmount</th>
    <th runat="server">OrderID</th>
    <th runat="server">OrderItemsId</th>
    </tr>
    <tr id="itemPlaceholder" runat="server">
    </tr>
    </table>
    </td>
    </tr>
    <tr runat="server">
    <td runat="server" style=""></td>
    </tr>
    </table>
    </LayoutTemplate>
    <SelectedItemTemplate>
    <tr style="">
    <td>
    <asp:Button ID="DeleteButton" runat="server" CommandName="Delete" Text="Delete" />
    <asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" />
    </td>
    <td>
    <asp:Label ID="ItemNameLabel" runat="server" Text='<%# Eval("ItemName") %>' />
    </td>
    <td>
    <asp:Label ID="QuantityLabel" runat="server" Text='<%# Eval("Quantity") %>' />
    </td>
    <td>
    <asp:Label ID="RateLabel" runat="server" Text='<%# Eval("Rate") %>' />
    </td>
    <td>
    <asp:Label ID="TotalAmountLabel" runat="server" Text='<%# Eval("TotalAmount") %>' />
    </td>
    <td>
    <asp:Label ID="OrderIDLabel" runat="server" Text='<%# Eval("OrderID") %>' />
    </td>
    <td>
    <asp:Label ID="OrderItemsIdLabel" runat="server" Text='<%# Eval("OrderItemsId") %>' />
    </td>
    </tr>
    </SelectedItemTemplate>
    </asp:ListView>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:LESFieldTicketConnectionString %>" DeleteCommand="DELETE FROM [OrderDetails] WHERE [OrderItemsId] = @OrderItemsId" InsertCommand="INSERT INTO [OrderDetails] ([ItemName], [Quantity], [Rate], [TotalAmount], [OrderID]) VALUES (@ItemName, @Quantity, @Rate, @TotalAmount, @OrderID)" SelectCommand="SELECT [ItemName], [Quantity], [Rate], [TotalAmount], [OrderItemsId], [OrderID] FROM [OrderDetails] WHERE ([OrderID] = @OrderID)" UpdateCommand="UPDATE [OrderDetails] SET [ItemName] = @ItemName, [Quantity] = @Quantity, [Rate] = @Rate, [TotalAmount] = @TotalAmount, [OrderID] = @OrderID WHERE [OrderItemsId] = @OrderItemsId">
    <DeleteParameters>
    <asp:Parameter Name="OrderItemsId" Type="Int32" />
    </DeleteParameters>
    <InsertParameters>
    <asp:Parameter Name="ItemName" Type="String" />
    <asp:Parameter Name="Quantity" Type="Int32" />
    <asp:Parameter Name="Rate" Type="Decimal" />
    <asp:Parameter Name="TotalAmount" Type="Decimal" />
    <asp:Parameter Name="OrderID" Type="Int32" />
    </InsertParameters>
    <SelectParameters>
    <asp:ControlParameter ControlID="txtOrderID" Name="OrderID" PropertyName="Text" Type="Int32" />
    </SelectParameters>
    <UpdateParameters>
    <asp:Parameter Name="ItemName" Type="String" />
    <asp:Parameter Name="Quantity" Type="Int32" />
    <asp:Parameter Name="Rate" Type="Decimal" />
    <asp:Parameter Name="TotalAmount" Type="Decimal" />
    <asp:Parameter Name="OrderID" Type="Int32" />
    <asp:Parameter Name="OrderItemsId" Type="Int32" />
    </UpdateParameters>
    </asp:SqlDataSource>
    <br />
    </div>
    </form>
    </body>
    </html>

    Friday, May 11, 2018 3:44 PM

Answers

  • User-1716253493 posted

    Seem like you need to replace orderid parameter with controlparameter in insertparameters like you have it in selectparameters

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, May 14, 2018 8:47 PM

All replies

  • User283571144 posted

    Hi osupratt1234,

    i am wanting the value that is in a text box (txtOrderID) to pass into a column of the List View which is named OrderID. primary key of one table to foreign key of the detail table back-end SQL. (Orders to OrdersDetail).

    According to your description, I couldn't understand your issue clearly.

    According to your datasource1's select command, I found you select the OrderDetails table according to the OrderID and I found you add the select parameter which bind with txtOrderID textbox.

    Do you mean you want to add a new row with data to ListView1 by select the OrdersDetail with OrderID or you want to select  OrdersDetail and Orders table data and show in the listview?

    I suggest you could post more details information about your requirement, if you could post more details information.

    It will be more easily for us to find the solution.

    Best Regards,

    Brando

    Monday, May 14, 2018 7:40 AM
  • User-1716253493 posted

    OrderID datakey is equal to txtOrderID.Text

    You can use txtOrderID as controlparameter

    I don't understand what the problem

    Monday, May 14, 2018 8:37 AM
  • User-1016229741 posted

    i'm very new and sorry for not seeing exactly where to try this at. i show this in my html already is it not the same as what you are saying? i believe you are giving me what i need and thank you very much but not sure where to apply it. 

    <SelectParameters>
    <asp:ControlParameter ControlID="txtOrderID" Name="OrderID" PropertyName="Text" Type="Int32" />
    </SelectParameters>

    thank you.

    Monday, May 14, 2018 1:31 PM
  • User-1016229741 posted

    the problem is if i type in '3' in txtOrderID text box and then click btnSubmit it works where any row in table with the OrderID=3 will show. BUT on a new record or an empty record i would like to have the value in txtOrderID also be in the List View column OrderID. so if the end-user types a '3' in text box and clicks submit a new blank record should show so she can enter in information but the value 3 should already be in the List View column so end-user can't mess it up. (just an example but that is what is wrong). value doesn't bind or fill or pass or whatever terminology is used. thanks.

    Monday, May 14, 2018 1:51 PM
  • User-1716253493 posted

    Seem like you need to replace orderid parameter with controlparameter in insertparameters like you have it in selectparameters

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, May 14, 2018 8:47 PM
  • User-1016229741 posted

    thanks so much for the reply. i've moved to put everything in code-behind. i have the basics working just fine. i have a couple questions on adding a drop down list inside the list view but will create a new post as it is a bit off this topic. thank you oned_gk and brando.

    Tuesday, May 15, 2018 7:19 PM