Click here to Skip to main content
15,922,630 members
Home / Discussions / ASP.NET
   

ASP.NET

 
GeneralRe: Asp 2.0 Gridview/SqlDataSource update/delete problem Pin
minhpc_bk15-Jun-06 8:15
minhpc_bk15-Jun-06 8:15 
QuestionDynamically Generated Columns in DataGrid Pin
alexfromto14-Jun-06 3:43
alexfromto14-Jun-06 3:43 
AnswerRe: Dynamically Generated Columns in DataGrid Pin
ToddHileHoffer14-Jun-06 7:53
ToddHileHoffer14-Jun-06 7:53 
GeneralRe: Dynamically Generated Columns in DataGrid Pin
alexfromto14-Jun-06 9:30
alexfromto14-Jun-06 9:30 
AnswerRe: Dynamically Generated Columns in DataGrid Pin
minhpc_bk14-Jun-06 20:10
minhpc_bk14-Jun-06 20:10 
GeneralRe: Dynamically Generated Columns in DataGrid Pin
alexfromto15-Jun-06 8:16
alexfromto15-Jun-06 8:16 
GeneralRe: Dynamically Generated Columns in DataGrid Pin
minhpc_bk15-Jun-06 16:47
minhpc_bk15-Jun-06 16:47 
GeneralRe: Dynamically Generated Columns in DataGrid [modified] Pin
alexfromto16-Jun-06 3:02
alexfromto16-Jun-06 3:02 
Done that. Works fine. The only problem I have is, like I've mentioned before, is to store totals of all orders. For example, when I do ItemCreated even handler I'm able to calculate total for specific item and store it in Label or TextBox. But I cannot calculate total for all items. In my event handler every time I calculate item total I've tried to add it to grandtotal global varailbe that I've put at the top of my class (global variable) but for some reason it doen't work. I'm not sure why!!!

Public Class DataGridTemplate
Implements ITemplate
Dim templateType As ListItemType
Dim columnName1 As String
Dim columnName2 As String
Dim mode As Integer
Dim grandtotalweight As Decimal

Sub New(ByVal type As ListItemType, ByVal ColName1 As String, ByVal ColName2 As String, ByVal md As Integer)
templateType = type
columnName1 = ColName1
columnName2 = ColName2
mode = md
grandtotalweight = 0
End Sub

Sub InstantiateIn(ByVal container As Control) _
Implements ITemplate.InstantiateIn
Dim lb As New Label
Dim tb As New TextBox
Select Case templateType
Case ListItemType.Header
lb.Text = "" & columnName1 & ""
container.Controls.Add(lb)
Case ListItemType.Item
AddHandler lb.DataBinding, AddressOf BindDataWeights
container.Controls.Add(lb)
Case ListItemType.EditItem
tb.Text = ""
container.Controls.Add(tb)
Case ListItemType.Footer
lb.Text = "Footer"
container.Controls.Add(lb)
End Select
End Sub

Sub BindDataWeights(ByVal Sender As Object, ByVal e As EventArgs)
Dim lb As Label = CType(Sender, Label)
Dim Container As DataGridItem = CType(lb.NamingContainer, DataGridItem)

Dim qty As Integer = DataBinder.Eval(Container.DataItem, columnName1)
Dim sku As String = DataBinder.Eval(Container.DataItem, columnName2)

Dim total As Decimal = GetWeights(qty, sku)
lb.Text = Format(total, "0.00")
End Sub

Function GetWeights(ByVal qty As Integer, ByVal sku As String) As Decimal
Dim con As System.Data.SqlClient.SqlConnection
Dim rdr As System.Data.SqlClient.SqlDataReader
Dim weight As Decimal = 0
Try
con = New System.Data.SqlClient.SqlConnection
con.ConnectionString = "connection string goes here"
con.Open()

Dim cmd As New System.Data.SqlClient.SqlCommand("SELECT * FROM Weights WHERE itm_sku=@i_sku", con)
cmd.Parameters.Add("@i_sku", sku)
rdr = cmd.ExecuteReader()

Do While rdr.Read()
weight = rdr("itm_wght")
Loop

rdr.Close()
con.Close()
Catch ex As Exception
con.Close()
'Display error message
End Try
' This is where I try to sotre total weights in the grandtotalweight variable
' But when I access it later on it returns 0
grandtotalweight += weight * qty
Return weight * qty
End Function
End Class

-- modified at 9:02 Friday 16th June, 2006
GeneralRe: Dynamically Generated Columns in DataGrid Pin
minhpc_bk17-Jun-06 19:51
minhpc_bk17-Jun-06 19:51 
GeneralRe: Dynamically Generated Columns in DataGrid Pin
alexfromto19-Jun-06 2:56
alexfromto19-Jun-06 2:56 
GeneralRe: Dynamically Generated Columns in DataGrid Pin
minhpc_bk19-Jun-06 10:19
minhpc_bk19-Jun-06 10:19 
GeneralRe: Dynamically Generated Columns in DataGrid Pin
alexfromto19-Jun-06 11:00
alexfromto19-Jun-06 11:00 
QuestionTarget attribute of ASP:HyperLink Pin
peshawarcoder14-Jun-06 3:43
peshawarcoder14-Jun-06 3:43 
AnswerRe: Target attribute of ASP:HyperLink Pin
ToddHileHoffer14-Jun-06 4:03
ToddHileHoffer14-Jun-06 4:03 
Questionasp.net 2.0 Pin
ssamriti14-Jun-06 3:40
ssamriti14-Jun-06 3:40 
AnswerRe: asp.net 2.0 Pin
ToddHileHoffer14-Jun-06 3:53
ToddHileHoffer14-Jun-06 3:53 
QuestionDomCompareValidator Problem Pin
Praveen_S14-Jun-06 3:35
Praveen_S14-Jun-06 3:35 
AnswerRe: DomCompareValidator Problem Pin
Mircea Grelus14-Jun-06 8:42
Mircea Grelus14-Jun-06 8:42 
QuestionReapreter control problem Pin
Nagraj Naik14-Jun-06 3:34
Nagraj Naik14-Jun-06 3:34 
AnswerRe: Reapreter control problem Pin
Elina Blank14-Jun-06 4:28
sitebuilderElina Blank14-Jun-06 4:28 
GeneralRe: Reapreter control problem Pin
Nagraj Naik14-Jun-06 19:04
Nagraj Naik14-Jun-06 19:04 
GeneralRe: Reapreter control problem Pin
Elina Blank15-Jun-06 3:27
sitebuilderElina Blank15-Jun-06 3:27 
QuestionCount Visitors Pin
TheEagle14-Jun-06 3:26
TheEagle14-Jun-06 3:26 
AnswerRe: Count Visitors Pin
amaneet14-Jun-06 4:04
amaneet14-Jun-06 4:04 
GeneralRe: Count Visitors Pin
TheEagle14-Jun-06 4:15
TheEagle14-Jun-06 4:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.