0
私は2つのitemTemplateをGridviewに持っており、乗算演算を実行し、それを別の列に格納する必要があります。すなわちproductPrice
およびproductQuantity
を掛けてtotalPrice
ラベルに格納します。サンキューGridview Itemtemplateでの計算?
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:AutopartConnectionString %>"
SelectCommand="SELECT [id], [productID], [productName], [productPrice], [productQuantity], [totalPrice] FROM [cartDetails]"
UpdateCommand="UPDATE [cartDetails] SET [productQuantity][email protected] WHERE [productID][email protected]"
DeleteCommand="DELETE [cartDetails] WHERE [productID][email protected]">
<%--<UpdateParameters>
<asp:Parameter Name="productQuantity" Type="Int32" />
<asp:Parameter Name="productQuantity" Type="String" />
</UpdateParameters>--%>
<DeleteParameters>
<asp:Parameter Name="productID" Type="Int32" />
</DeleteParameters>
</asp:SqlDataSource>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="id" DataSourceID="SqlDataSource1">
<Columns>
<asp:TemplateField HeaderText="id" InsertVisible="False" SortExpression="id" Visible="False">
<EditItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("id") %>'></asp:Label>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("id") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="productID" SortExpression="productID" >
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Eval("productID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="productName" SortExpression="productName">
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Eval("productName") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="productPrice" SortExpression="productPrice">
<ItemTemplate>
<asp:Label ID="Label4" runat="server" Text='<%# Eval("productPrice") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="productQuantity" SortExpression="productQuantity">
<EditItemTemplate>
<asp:TextBox ID="TextBox4" runat="server" Text='<%# Eval("productQuantity") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label5" runat="server" Text='<%# Eval("productQuantity") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowEditButton="True" />
<asp:TemplateField HeaderText="totalPrice" SortExpression="totalPrice">
<ItemTemplate>
<asp:Label ID="Label6" runat="server" Text='<%# ((Convert.ToDecimal(Eval("productPrice")))*(Convert.ToDecimal(Eval("productQuantity")))).ToString() %>'></asp:Label>
<%-- <asp:Label ID="Label6" runat="server" Text='<%# Bind("totalPrice") %>'></asp:Label>--%>
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowDeleteButton="True" />
</Columns>
</asp:GridView>
私のテーブル構造
Create table cartDetails(
id int not null identity(1,1) primary key,
productID int not null,
productName VARCHAR(150) not null ,
productPrice float,
productQuantity int,
totalPrice float
);
コードを実行するとどうなりますか?あなたは 'totalPrice'に何かを見ますか? – ConnorsFan
@ConnorsFanコンパイラエラーメッセージ:CS0103: 'Bind'という名前は現在のコンテキストに存在しません。 ' – adarshjaya12
OK。したがって、計算列がなくても、いくつか問題があるはずです。すべての列で 'Bind'を' Eval'に置き換えることができます。 – ConnorsFan