gtjr92
05-16-2005, 04:31 AM
I am trying to get the totals for rows and thenshow them in a footer, I keep getting
"Message="Index was out of range. Must be non-negative and less than the size of the collection."
System.ArgumentOutOfRangeException was unhandled by user code
Message="Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index"
ParamName="index"
Source="mscorlib"
for this line Dim TitheCount As Double = (CDbl(GridView1.Rows.Item(6).Cells.ToString()))
Here is my code
[quote]
Dim TitheCountSum As Double = 0
Public Sub ComputeSum(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
If e.Row.RowType = ListItemType.Item Or _
e.Row.RowType = ListItemType.AlternatingItem Then
Dim TitheCount As Double = (CDbl(GridView1.Rows.Item(6).Cells.ToString()))
TitheCountSum += TitheCount
End If
If e.Row.RowType = DataControlCellType.Footer Then
GridView1.FooterRow.Cells(5).Text = "Total Ti: " & String.Format("{0:C}", TitheCountSum)
End If
End Sub</CODE>
ASP Code
[quote]
<asp:GridView ID="GridView1" runat="server" AllowSorting="True" AutoGenerateColumns="False" ShowFooter="True" DataSourceID="dsoTithe" BackColor="#FFFFC0" BorderColor="Olive" BorderStyle="Solid" CellPadding="1" CellSpacing="1" ForeColor="Blue" DataKeyNames="TRID"
OnRowDataBound="computesum">
<Columns>
<asp:BoundField DataField="TRID" HeaderText="TRID" InsertVisible="False" SortExpression="TRID" Visible=False/>
<asp:BoundField DataField="WkID" HeaderText="WkID" SortExpression="WkID" />
<asp:BoundField DataField="Name" HeaderText="Name"/>
<asp:TemplateField HeaderText="Date" SortExpression="Date">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("Weeks_Date", "{0:d}") %>' ></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Weeks_Date") %>' ReadOnly=true></asp:TextBox>
</EditItemTemplate>
<ItemStyle Width="35px" />
</asp:TemplateField>
<asp:BoundField DataField="People_ID" HeaderText="People_ID" SortExpression="People_ID" Visible="False"/>
<asp:TemplateField HeaderText="Tithe" SortExpression="Tithe" >
<ItemTemplate>
<asp:TextBox ID="TxtTithe" runat="server" Width="90px" Text='<%# Bind("Tithe", "{0:c}")%>'> </asp:TextBox>
</ItemTemplate>
<ItemStyle Width="25px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Education" SortExpression="Education">
<ItemTemplate>
<asp:TextBox ID="TxtEducation" runat="server" Width="90px" Text='<%# Bind("Education","{0:c}") %>'></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Missions" SortExpression="Missions">
<ItemTemplate>
<asp:TextBox ID="TxtMission" runat="server" Width="90px" Text='<%# Bind("Missions", "{0:c}") %>'></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Special" SortExpression="Special">
<ItemTemplate>
<asp:TextBox ID="TxtSpecial" runat="server" Width="90px" Text='<%# Bind("Special", "{0:c}") %>'></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Gift_Item" SortExpression="Gift_Item">
<ItemTemplate>
<asp:TextBox ID="TxtGItem" runat="server" Width="90px" Text='<%# Bind("Gift_Item") %>'></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Gift_Value" SortExpression="Gift_Value">
<ItemTemplate>
<asp:TextBox ID="TxtGValue" runat="server" Width="90px" Text='<%# Bind("Gift_Value","{0:c}" ) %>'></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BorderColor="#E0E0E0" HorizontalAlign="Center" VerticalAlign="Middle" BackColor="PaleGoldenrod" BorderStyle="Double" Font-Italic="True" Font-Overline="False" ForeColor="Goldenrod" />
<RowStyle BackColor="Navy" BorderStyle="Solid" Font-Size="10pt" ForeColor="Gainsboro" />
<AlternatingRowStyle BackColor="Gray" BorderStyle="Solid" ForeColor="Navy" />
</asp:GridView>
"Message="Index was out of range. Must be non-negative and less than the size of the collection."
System.ArgumentOutOfRangeException was unhandled by user code
Message="Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index"
ParamName="index"
Source="mscorlib"
for this line Dim TitheCount As Double = (CDbl(GridView1.Rows.Item(6).Cells.ToString()))
Here is my code
[quote]
Dim TitheCountSum As Double = 0
Public Sub ComputeSum(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
If e.Row.RowType = ListItemType.Item Or _
e.Row.RowType = ListItemType.AlternatingItem Then
Dim TitheCount As Double = (CDbl(GridView1.Rows.Item(6).Cells.ToString()))
TitheCountSum += TitheCount
End If
If e.Row.RowType = DataControlCellType.Footer Then
GridView1.FooterRow.Cells(5).Text = "Total Ti: " & String.Format("{0:C}", TitheCountSum)
End If
End Sub</CODE>
ASP Code
[quote]
<asp:GridView ID="GridView1" runat="server" AllowSorting="True" AutoGenerateColumns="False" ShowFooter="True" DataSourceID="dsoTithe" BackColor="#FFFFC0" BorderColor="Olive" BorderStyle="Solid" CellPadding="1" CellSpacing="1" ForeColor="Blue" DataKeyNames="TRID"
OnRowDataBound="computesum">
<Columns>
<asp:BoundField DataField="TRID" HeaderText="TRID" InsertVisible="False" SortExpression="TRID" Visible=False/>
<asp:BoundField DataField="WkID" HeaderText="WkID" SortExpression="WkID" />
<asp:BoundField DataField="Name" HeaderText="Name"/>
<asp:TemplateField HeaderText="Date" SortExpression="Date">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("Weeks_Date", "{0:d}") %>' ></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Weeks_Date") %>' ReadOnly=true></asp:TextBox>
</EditItemTemplate>
<ItemStyle Width="35px" />
</asp:TemplateField>
<asp:BoundField DataField="People_ID" HeaderText="People_ID" SortExpression="People_ID" Visible="False"/>
<asp:TemplateField HeaderText="Tithe" SortExpression="Tithe" >
<ItemTemplate>
<asp:TextBox ID="TxtTithe" runat="server" Width="90px" Text='<%# Bind("Tithe", "{0:c}")%>'> </asp:TextBox>
</ItemTemplate>
<ItemStyle Width="25px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Education" SortExpression="Education">
<ItemTemplate>
<asp:TextBox ID="TxtEducation" runat="server" Width="90px" Text='<%# Bind("Education","{0:c}") %>'></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Missions" SortExpression="Missions">
<ItemTemplate>
<asp:TextBox ID="TxtMission" runat="server" Width="90px" Text='<%# Bind("Missions", "{0:c}") %>'></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Special" SortExpression="Special">
<ItemTemplate>
<asp:TextBox ID="TxtSpecial" runat="server" Width="90px" Text='<%# Bind("Special", "{0:c}") %>'></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Gift_Item" SortExpression="Gift_Item">
<ItemTemplate>
<asp:TextBox ID="TxtGItem" runat="server" Width="90px" Text='<%# Bind("Gift_Item") %>'></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Gift_Value" SortExpression="Gift_Value">
<ItemTemplate>
<asp:TextBox ID="TxtGValue" runat="server" Width="90px" Text='<%# Bind("Gift_Value","{0:c}" ) %>'></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BorderColor="#E0E0E0" HorizontalAlign="Center" VerticalAlign="Middle" BackColor="PaleGoldenrod" BorderStyle="Double" Font-Italic="True" Font-Overline="False" ForeColor="Goldenrod" />
<RowStyle BackColor="Navy" BorderStyle="Solid" Font-Size="10pt" ForeColor="Gainsboro" />
<AlternatingRowStyle BackColor="Gray" BorderStyle="Solid" ForeColor="Navy" />
</asp:GridView>