Когда я попытаюсь отредактировать данные, он выдаст ошибку "входная строка была не в правильном формате". в строке "totalpc=totalpc+convert.toint32(row.cells[2].text)"
private void calculateSum() { Int32 TotalPC = 0; foreach (GridViewRow row in GridView1.Rows) { TotalPC = TotalPC + Convert.ToInt32(row.Cells[2].Text); } GridView1.FooterRow.Cells[1].Text = "Total PC"; GridView1.FooterRow.Cells[2].Text = TotalPC.ToString(); } protected void GridView1_DataBound(object sender, EventArgs e) { calculateSum(); }
Что я уже пробовал:
<form id="form1" runat="server"> <h2><a href="/KB/answers/Mainpage.aspx" style="color:darkorange;text-decoration:none">Total User PCs in Active</a></h2> <div> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" DeleteCommand="DELETE FROM [TotalAll] WHERE [No] = @No" InsertCommand="INSERT INTO [TotalAll] ([No], [Department], [TotalPC]) VALUES (@No, @Department, @TotalPC)" SelectCommand="SELECT * FROM [TotalAll]" UpdateCommand="UPDATE [TotalAll] SET [Department] = @Department, [TotalPC] = @TotalPC WHERE [No] = @No"> <DeleteParameters> <asp:Parameter Name="No" Type="Int32" /> </DeleteParameters> <InsertParameters> <asp:Parameter Name="No" Type="Int32" /> <asp:Parameter Name="Department" Type="String" /> <asp:Parameter Name="TotalPC" Type="Int32" /> </InsertParameters> <UpdateParameters> <asp:Parameter Name="Department" Type="String" /> <asp:Parameter Name="TotalPC" Type="Int32" /> <asp:Parameter Name="No" Type="Int32" /> </UpdateParameters> </asp:SqlDataSource> <br /> <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" BackColor="White" BorderColor="#CC9966" BorderStyle="None" BorderWidth="1px" CellPadding="4" DataKeyNames="No" DataSourceID="SqlDataSource1" OnDataBound="GridView1_DataBound" ShowFooter="True" > <Columns> <asp:BoundField DataField="No" HeaderText="No" ReadOnly="True" SortExpression="No" /> <asp:BoundField DataField="Department" HeaderText="Department" SortExpression="Department" /> <asp:BoundField DataField="TotalPC" HeaderText="TotalPC" SortExpression="TotalPC" /> <asp:CommandField HeaderText="Operation" ShowEditButton="True" /> </Columns> <FooterStyle BackColor="#FFFFCC" ForeColor="#330099" /> <HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="#FFFFCC" /> <PagerStyle BackColor="#FFFFCC" ForeColor="#330099" HorizontalAlign="Center" /> <RowStyle BackColor="White" ForeColor="#330099" /> <SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="#663399" /> <SortedAscendingCellStyle BackColor="#FEFCEB" /> <SortedAscendingHeaderStyle BackColor="#AF0101" /> <SortedDescendingCellStyle BackColor="#F6F0C0" /> <SortedDescendingHeaderStyle BackColor="#7E0000" /> </asp:GridView> </div> </form>