Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/283.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在“上编码”;“添加到购物车”;按钮_C#_Asp.net - Fatal编程技术网

C# 如何在“上编码”;“添加到购物车”;按钮

C# 如何在“上编码”;“添加到购物车”;按钮,c#,asp.net,C#,Asp.net,我正在使用列表视图,请告诉我如何从列表视图模板中选择特定项。在listview模板中,我使用了一个名为“添加到购物车”的按钮。以及如何将产品添加到购物车页面 <asp:ListView ID="ListView1" runat="server" DataSourceID="SqlDataSource1" GroupItemCount="5"> <AlternatingItemTemplate> <td runat="serv

我正在使用列表视图,请告诉我如何从列表视图模板中选择特定项。在listview模板中,我使用了一个名为“添加到购物车”的按钮。以及如何将产品添加到购物车页面

    <asp:ListView ID="ListView1" runat="server" DataSourceID="SqlDataSource1" 
    GroupItemCount="5">
    <AlternatingItemTemplate>
        <td runat="server" style="background-color:#FFF8DC;">
            <asp:Image ID="Image2" runat="server" Height="101px" 
                ImageUrl='<%# Eval("img") %>' Width="100px" />
            <br />
            Title:
            <asp:Label ID="titleLabel" runat="server" Text='<%# Eval("title") %>' />
            <br />author:
            <asp:Label ID="authorLabel" runat="server" Text='<%# Eval("author") %>' />
            <br />publisher:
            <asp:Label ID="publisherLabel" runat="server" Text='<%# Eval("publisher") %>' />
            <br />price:
            <asp:Label ID="priceLabel" runat="server" Text='<%# Eval("price") %>' />
            <br />
            <asp:Button ID="Button4" runat="server" Text="Add to Cart" 
                OnClick="Button4_Click" PostBackUrl="~/ShoppingCart.aspx" />
            <br />
        </td>
    </AlternatingItemTemplate>
    <EditItemTemplate>
        <td runat="server" style="background-color:#FFF8DC;">
            <asp:Image ID="Image2" runat="server" Height="101px" 
                ImageUrl='<%# Eval("img") %>' Width="100px" />
            <br />
            Title:
            <asp:Label ID="titleLabel" runat="server" Text='<%# Eval("title") %>'></asp:Label>
            <br />author:
            <asp:Label ID="authorLabel" runat="server" Text='<%# Eval("author") %>'></asp:Label>
            <br />publisher:
            <asp:Label ID="publisherLabel" runat="server" Text='<%# Eval("publisher") %>'></asp:Label>
            <br />price:
            <asp:Label ID="priceLabel" runat="server" Text='<%# Eval("price") %>'></asp:Label>
            <br />
            <asp:Button ID="Button4" runat="server" 
                Text="Add to Cart" OnClick="Button4_Click" 
                OnClientClick='<%# Eval("title", "{0}") %>' PostBackUrl="~/ShoppingCart.aspx" />
            <br />
        </td>
    </EditItemTemplate>
    <EmptyDataTemplate>
        <table runat="server" 
            style="background-color: #FFFFFF;border-collapse: collapse;border-color: #999999;border-style:none;border-width:1px;">
            <tr>
                <td>
                    No data was returned.</td>
            </tr>
        </table>
    </EmptyDataTemplate>
    <EmptyItemTemplate>
<td runat="server" />
    </EmptyItemTemplate>
    <GroupTemplate>
        <tr ID="itemPlaceholderContainer" runat="server">
            <td ID="itemPlaceholder" runat="server">
            </td>
        </tr>
    </GroupTemplate>
    <InsertItemTemplate>
        <td runat="server" style="">
            title:
            <asp:TextBox ID="titleTextBox" runat="server" Text='<%# Bind("title") %>' />
            <br />author:
            <asp:TextBox ID="authorTextBox" runat="server" Text='<%# Bind("author") %>' />
            <br />publisher:
            <asp:TextBox ID="publisherTextBox" runat="server" 
                Text='<%# Bind("publisher") %>' />
            <br />price:
            <asp:TextBox ID="priceTextBox" runat="server" Text='<%# Bind("price") %>' />
            <br />img:
            <asp:TextBox ID="imgTextBox" runat="server" Text='<%# Bind("img") %>' />
            <br />
            <asp:Button ID="InsertButton" runat="server" CommandName="Insert" 
                Text="Insert" />
            <br />
            <asp:Button ID="CancelButton" runat="server" CommandName="Cancel" 
                Text="Clear" />
            <br />
        </td>
    </InsertItemTemplate>
    <ItemTemplate>
        <td runat="server" style="background-color:#DCDCDC;color: #000000;">
            <asp:Image ID="Image1" runat="server" Height="100px" 
                ImageUrl='<%# Eval("img") %>' Width="101px" />
            <br />
            Title:
            <asp:Label ID="titleLabel" runat="server" Text='<%# Eval("title") %>' />
            <br />Author:
            <asp:Label ID="authorLabel" runat="server" Text='<%# Eval("author") %>' />
            <br />Publisher:
            <asp:Label ID="publisherLabel" runat="server" Text='<%# Eval("publisher") %>' />
            <br />Price:
            <asp:Label ID="priceLabel" runat="server" Text='<%# Eval("price") %>' />
            <br />
            <asp:Button ID="Button3" runat="server" Text="Add to Cart" 
                OnClientClick='<%# Eval("title", "{0}") %>' />
            <br />
        </td>
    </ItemTemplate>
    <LayoutTemplate>
        <table runat="server">
            <tr runat="server">
                <td runat="server">
                    <table ID="groupPlaceholderContainer" runat="server" border="1" 
                        style="background-color: #FFFFFF;border-collapse: collapse;border-color: #999999;border-style:none;border-width:1px;font-family: Verdana, Arial, Helvetica, sans-serif;">
                        <tr ID="groupPlaceholder" runat="server">
                        </tr>
                    </table>
                </td>
            </tr>
            <tr runat="server">
                <td runat="server" 
                    style="text-align: center;background-color: #CCCCCC;font-family: Verdana, Arial, Helvetica, sans-serif;color: #000000;">
                </td>
            </tr>
        </table>
    </LayoutTemplate>
    <SelectedItemTemplate>
        <td runat="server" 
            style="background-color:#008A8C;font-weight: bold;color: #FFFFFF;">
            title:
            <asp:Label ID="titleLabel" runat="server" Text='<%# Eval("title") %>' />
            <br />author:
            <asp:Label ID="authorLabel" runat="server" Text='<%# Eval("author") %>' />
            <br />publisher:
            <asp:Label ID="publisherLabel" runat="server" Text='<%# Eval("publisher") %>' />
            <br />price:
            <asp:Label ID="priceLabel" runat="server" Text='<%# Eval("price") %>' />
            <br />img:
            <asp:Label ID="imgLabel" runat="server" Text='<%# Eval("img") %>' />
            <br />
        </td>
    </SelectedItemTemplate>

</asp:ListView>


标题:
作者:
出版商:
价格:


标题:
作者:
出版商:
价格:

没有返回任何数据。 标题:
作者:
出版商:
价格:
img:



标题:
作者:
出版商:
价格:

标题:
作者:
出版商:
价格:
img:

将命令与按钮和列表视图项命令事件一起使用

Aspx页面:

<asp:ListView ID="ListView1" runat="server" DataSourceID="AccessDataSource1" 
    GroupItemCount="3"  ItemPlaceholderID="itemPlaceholder" DataKeyNames="Id">

  <asp:Button ID="cartbtn" Text="Add To cart" runat="server" ForeColor="Blue" Font-Underline="true" CommandName="Add" ></asp:Button>

    </ListView>

不需要那些额外的东西,特别是在你的问题标题中。我不能给你源代码,但你可以使用控件的itemcommand事件,这将达到目的。请解释过程…请参考
      protected void ListView1_ItemCommand(object sender, ListViewCommandEventArgs e)
    {       
        if (e.CommandName.ToString()=="Add")
        {
           //Write your code Here
        }
    }