View Single Post
  #1 (permalink)  
Old December 27th, 2006, 11:41 AM
sarah lee sarah lee is offline
Friend of Wrox
 
Join Date: Aug 2006
Location: norcross, Ga, USA.
Posts: 107
Thanks: 0
Thanked 0 Times in 0 Posts
Default display sum in footer of gridview

hi all

I am trying to display sum in the footer of a gridview., i am getting the following error.

can anyone please tel me what can be the reason

Specified argument was out of the range of valid values.
Parameter name: index
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values.
Parameter name: index

Source Error:



Line 44:
Line 45: Dim unitprice As Decimal = Convert.ToDecimal(e.Row.Cells(2).Text)
Line 46: Dim t As TextBox = CType(e.Row.Cells(3).Controls(1), TextBox)
Line 47:
Line 48: Dim quantity As Integer = Integer.Parse(t.Text)




Source File: C:\VS2003\ShoppingCart3VB\example.aspx.vb Line: 46

Stack Trace:



[ArgumentOutOfRangeException: Specified argument was out of the range of valid values.
Parameter name: index]
   System.Web.UI.ControlCollection.get_Item(Int32 index) +69
   example.GridView1_RowDataBound(Object sender, GridViewRowEventArgs e) in C:\VS2003\ShoppingCart3VB\example.aspx.vb:46
   System.Web.UI.WebControls.GridView.OnRowDataBound( GridViewRowEventArgs e) +75
   System.Web.UI.WebControls.GridView.CreateRow(Int32 rowIndex, Int32 dataSourceIndex, DataControlRowType rowType, DataControlRowState rowState, Boolean dataBind, Object dataItem, DataControlField[] fields, TableRowCollection rows, PagedDataSource pagedDataSource) +233
   System.Web.UI.WebControls.GridView.CreateChildCont rols(IEnumerable dataSource, Boolean dataBinding) +3008
   System.Web.UI.WebControls.CompositeDataBoundContro l.PerformDataBinding(IEnumerable data) +59
   System.Web.UI.WebControls.GridView.PerformDataBind ing(IEnumerable data) +12
   System.Web.UI.WebControls.DataBoundControl.OnDataS ourceViewSelectCallback(IEnumerable data) +101
   System.Web.UI.DataSourceView.Select(DataSourceSele ctArguments arguments, DataSourceViewSelectCallback callback) +25
   System.Web.UI.WebControls.DataBoundControl.Perform Select() +140
   System.Web.UI.WebControls.BaseDataBoundControl.Dat aBind() +68
   System.Web.UI.WebControls.GridView.DataBind() +5
   example.FillCartFromDB() in C:\VS2003\ShoppingCart3VB\example.aspx.vb:31
   example.Page_Load(Object sender, EventArgs e) in C:\VS2003\ShoppingCart3VB\example.aspx.vb:19
   System.EventHandler.Invoke(Object sender, EventArgs e) +0
   System.Web.UI.Control.OnLoad(EventArgs e) +80
   System.Web.UI.Control.LoadRecursive() +49
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3745





the code which i used is

Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound

If e.Row.RowType = DataControlRowType.DataRow Then

Dim unitprice As Decimal = Convert.ToDecimal(e.Row.Cells(2).Text)

Dim t As TextBox = CType(e.Row.Cells(3).Controls(1), TextBox)

Dim quantity As Integer = Integer.Parse(t.Text)

total = total + (unitprice * quantity)

'ElseIf e.Row.RowType= DataControlRowType.Footer Then

e.Row.Cells(3).Text = "Total Amount : " & total.ToString("c")

'End If

end Sub
thanks