数量テキストボックスに値を入力できるようにしたい場合:
- その値に「単位平方フィート」を掛けて、結果を「小計」に格納します。
- 各小計を合計し、結果を「Total」に格納します
これは私がこれまでに持っているものです:
<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 を使用してみました。次に、関連するコントロールを int に変換して乗算し、値をラベルに表示しようとしましたが、unitSquareFootLabel に関する null 参照を取得します。
しかし、上記のコードビハインドでは、入力文字列が正しい形式ではありません。
どうすればいいですか?