problem in add totals in datagrid
hi,
I have this asp.net script that supposed to get total of
records.But when i run it i get this error.
System.FormatException: Input string was not in a correct format.
Source Error:
Line 310: calctotal(e.Item.Cells(3).Text)
Line 311: e.Item.Cells(3).Text = String.Format("{0:n}", Convert.ToDouble(e.Item.Cells(3).Text))
Line 312:
Line 313: ElseIf (e.Item.ItemType = ListItemType.Footer) Then
i get null value at this line Response.Write(e.Item.Cells(3).Text).can anybody tell me how to fix it?
here is code
Partial Class first
Inherits System.Web.UI.Page
Private rtotal As Double = 0
'protected DataGrid DataGrid1
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim s, s2, fyear As String
s = (Request.QueryString("strtxt"))
Response.Write(s)
fyear = (Request.QueryString("strtxt2"))
Response.Write(fyear)
fyear = "20072008"
'Dim strTxtTransfer As String = Request.QueryString("strTxt")
'Response.Write(strTxtTransfer)
Dim sql_str, sqls As String
If Mid(s, 1, 2) = "TO" Then
sql_str = "Select t.store_invoice_no Inv,c.customer_name customer, to_char(t.invoice_date,'dd/mm/yyyy')inv_dat, t.store_item_pcs pcs, t.store_item_tot_pcs tot_pcs, nvl(t.no_of_packets,1) packets from ho_store_transaction t, customer_master c where store_challan_no= '" & s & "' and t.store_customer_code=c.customer_code and t.store_financial_year_code ='" & fyear & "' and t.store_company_code='DD' and t.store_location_code='L020' UNION Select '','', 'Total',sum(t.store_item_pcs)t_qty1, sum(t.store_item_tot_pcs)t_pcs1, sum(t.no_of_packets)t_packets from ho_store_transaction t, customer_master c where store_challan_no= '" & s & "' and t.store_customer_code=c.customer_code and t.store_financial_year_code ='" & fyear & "' and t.store_company_code='DD' and t.store_location_code='L020'"
Else
'ElseIf Mid(s, 1, 1) = "R" Then
sql_str = "Select m.store_challan_no Inv, c.customer_name customer, to_char(m.store_challan_date,'dd/mm/yyyy')inv_dat, sum(t.store_item_pcs)pcs, sum(t.store_item_tot_pcs)tot_pcs, nvl(t.no_of_packets,1) packets from ho_store_master m, ho_store_transaction t,customer_master c where m.Store_trfout_flag='N' and m.store_challan_no = t.store_challan_no and m.store_customer_code = c.CUSTOMER_CODE and m.store_challan_no = '" & s & "' and to_char(m.store_challan_date,'dd/mm/yyyy')= to_char(t.store_challan_date,'dd/mm/yyyy') and m.store_financial_year_code='" & fyear & "' and m.store_company_code='DD' and m.store_location_code='L020' group by m.store_challan_no,m.store_challan_date,c.customer _name,t.no_of_packets UNION Select '', '', 'Total', sum(t.store_item_pcs)t_qty1, sum(t.store_item_tot_pcs)t_pcs1, nvl(sum(t.no_of_packets),1)t_packets from ho_store_master m, ho_store_transaction t,customer_master c where m.Store_trfout_flag='N' and m.store_challan_no = t.store_challan_no and m.store_customer_code = c.CUSTOMER_CODE and m.store_challan_no = '" & s & "' and to_char(m.store_challan_date,'dd/mm/yyyy')= to_char(t.store_challan_date,'dd/mm/yyyy') and m.store_financial_year_code='" & fyear & "' and m.store_company_code='DD' and m.store_location_code='L020' group by m.store_challan_no,m.store_challan_date,c.customer _name,t.no_of_packets"
End If
Dim str As String
Dim con As OracleConnection
str = "User Id=nfc;Password=nfc;Data Source=dh"
con = New OracleConnection(str)
con.Open()
Dim cmd As New OracleDataAdapter _
(sql_str, con)
Dim ds As Data.DataSet = New Data.DataSet()
cmd.Fill(ds, "ho_store_transaction")
'ds.Merge(ds2)
DataGrid1.DataSource = ds.Tables("ho_store_transaction")
DataGrid1.DataBind()
End Sub
Protected Sub DataGrid1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles DataGrid1.ItemDataBound
If (e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem) Then
Response.Write(e.Item.Cells(3).Text)
calctotal(e.Item.Cells(3).Text)
e.Item.Cells(3).Text = String.Format("{0:n}", Convert.ToDouble(e.Item.Cells(3).Text))
ElseIf (e.Item.ItemType = ListItemType.Footer) Then
e.Item.Cells(2).Text = "TOTAL:"
e.Item.Cells(3).Text = String.Format("{0:n}", rtotal)
End If
End Sub
Private Sub calctotal(ByVal _pcs As String)
If IsNumeric(_pcs) Then
Response.Write(_pcs)
rtotal += Double.Parse(_pcs)
End If
End Sub
End Class
please help.
thanks
|