Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.0 and 1.1 Basics
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old December 27th, 2006, 11:41 AM
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


  #2 (permalink)  
Old December 27th, 2006, 11:48 AM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

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

Try this instead:

Dim t as TextBox = CType(e.Item.Cells(3).Controls(1), TextBox)

If this errors out then either the cell you are referencing does not exist or there is only one control in the cell thus controls(1) does not exist.

-------------------------
I will only tell you how to do it, not do it for you.
Unless, of course, you want to hire me to do work for you.

^^Thats my signature
  #3 (permalink)  
Old December 27th, 2006, 11:55 AM
Friend of Wrox
 
Join Date: Aug 2006
Location: norcross, Ga, USA.
Posts: 107
Thanks: 0
Thanked 0 Times in 0 Posts
Default

but item is not supported by gridview control, right?

  #4 (permalink)  
Old December 27th, 2006, 12:36 PM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

I have not used a gridview control so I am not certain but i believe that is true. What you might want to try is something along the lines of:

GridViewRow row = Gridview.Rows[e.RowIndex];
        if (row != null)
        {

            TextBox txt= row.FindControl("yourtextbox") as TextBox;
            //do something with the text box control.
        }

-------------------------
I will only tell you how to do it, not do it for you.
Unless, of course, you want to hire me to do work for you.

^^Thats my signature
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Totaling columns in a footer row of a GridView psimonson ASP.NET 2.0 Basics 1 May 5th, 2008 01:34 PM
Sum of the fields in the report footer sudagnr Crystal Reports 0 April 3rd, 2008 07:07 AM
Disp Footer even no record in GridView Datasource mallikalapati ASP.NET 2.0 Professional 1 March 19th, 2008 02:23 AM
display diff header footer pallavijyo BOOK: Professional Crystal Reports for VS.NET 1 October 5th, 2005 03:56 PM
Display DataGrid footer after last row only demivolt ASP.NET 1.0 and 1.1 Professional 2 August 9th, 2005 08:39 AM



All times are GMT -4. The time now is 05:26 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.