我希望能够在数量文本框中输入一个值,然后:
- 将该值乘以其“单位平方英尺”并将结果存储到“小计”中
- 汇总每个小计并将结果存储到“总计”中
这是我到目前为止所拥有的:
<asp:GridView runat="server" ID="gridViewBuildOfficeSpace" AllowPaging="false"
AllowSorting="false" AutoGenerateDeleteButton="false"
AutoGenerateEditButton="false" AutoGenerateSelectButton="false"
AutoGenerateColumns="false" ShowFooter="true"
onrowdatabound="gridViewBuildOfficeSpace_RowDataBound">
<Columns>
<asp:BoundField DataField="Description" HeaderText="Description" />
<asp:BoundField DataField="Size" HeaderText="Size" />
<asp:BoundField DataField="Dimensions" HeaderText="Dimensions" />
<asp:TemplateField HeaderText="Unit Square Foot">
<ItemTemplate>
<asp:Label runat="server" ID="unitSquareFootLabel" Text='<%# Eval("UnitSquareFoot") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Quantity" >
<ItemTemplate>
<asp:TextBox AutoPostBack="true" ID="gridviewQuantityItem" runat="server"/>
</ItemTemplate>
<FooterTemplate>
<asp:Label ID="Label12" Text="Total Size: " runat="server" />
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="SubTotal">
<ItemTemplate>
<asp:Label ID="gridViewItemSubTotal" runat="server" />
</ItemTemplate>
<FooterTemplate>
<asp:Label ID="totalSizeDisplayLabel" runat="server" />
</FooterTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
代码背后:
protected void gridViewBuildOfficeSpace_RowDataBound(object sender, GridViewRowEventArgs e)
{
for (int i = 0; i < gridViewBuildOfficeSpace.Rows.Count; i++)
{
gridViewBuildOfficeSpace.Rows[i].Cells[5].Text = Convert.ToString(Convert.ToDouble(gridViewBuildOfficeSpace.Rows[i].Cells[3].Text)*Convert.ToDouble(gridViewBuildOfficeSpace.Rows[i].Cells[4].Text));
}
}
我尝试在 TextBox 中使用 OnTextChanged,然后尝试找到相关的控件以将它们转换为整数并将它们相乘并将值显示到标签中,但我要么得到关于 unitSquareFootLabel 的空引用。
但是使用上面的代码,我得到输入字符串的格式不正确。
我该怎么做?