Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Treeview checked value not go to server
Message
General information
Forum:
ASP.NET
Category:
Other
Title:
Treeview checked value not go to server
Miscellaneous
Thread ID:
00883955
Message ID:
00883955
Views:
44
I have a webform to let users add a new record to an SQLServer table as well as several records to a related child table. The parent table record gets values from textboxes on the form. The child table gets as many records as needed from checkboxes of features on the form.

I am using a three level MS Treeview control to display the checkboxes. I create the tree nodes by reading from the child table. I add checkboxes to the 3rd level, as the nodes are created. The user can expand the nodes down to the third level and click on as many boxes as they want. The save button for the form then calls an append routine and inserts one record into the parent table. It then reads the checked property of each of the third level nodes and inserts a record into the child table if the property is true. This is running on IIS 2003 with .netframework 7.3

The problem: When the page posts back to the append record routine it sometimes does not seem to carry the values of the boxes that were checked by the user but then sometimes it does.

I can actually trace through the code behind and see that on one trip the proper nodes have a checked= true value and then at a later time they will all be false. Does anyone know what might be causing this?

The maketreeview code and the save/append record code is below


Sub maketreeview()
Dim strMajcat As String
Dim strSubcat As String
Dim strFeatureName As String
strMajcat = "Select distinct majcat from featurecd order by 1"
strSubcat = "Select distinct subcat, majcat, rtrim(majcat)+rtrim(subcat) as bothcat from featurecd order by 3"
strFeatureName = "Select featurename,sorder,subcat,majcat,rtrim(majcat)+rtrim(subcat) as bothcat,featurecd from featurecd order by 5,2"
Dim nodeMajCat As Microsoft.Web.UI.WebControls.TreeNode
Dim nodeSubcat As Microsoft.Web.UI.WebControls.TreeNode
Dim nodefeaturename As Microsoft.Web.UI.WebControls.TreeNode
Dim conc2a As System.Data.sqlclient.SqlConnection
Dim cmMajCat As SqlClient.SqlDataAdapter
Dim cmSubcat As SqlClient.SqlDataAdapter
Dim cmfeaturename As SqlClient.SqlDataAdapter
Dim ds As DataSet
Dim rowMajCat As DataRow
Dim rowSubcat As DataRow
Dim rowfeaturename As DataRow
conc2a = New System.Data.SqlClient.SqlConnection(System.Configuration.ConfigurationSettings.AppSettings("KeyConc2a"))
ds = New DataSet
conc2a.Open()
'Add 3 tables to the dataset
cmMajCat = New SqlClient.SqlDataAdapter(strMajcat, conc2a)
cmMajCat.Fill(ds, "MajCat")
cmSubcat = New SqlClient.SqlDataAdapter(strSubcat, conc2a)
cmSubcat.Fill(ds, "SubCat")
cmfeaturename = New SqlClient.SqlDataAdapter(strFeatureName, conc2a)
cmfeaturename.Fill(ds, "featurename")
'Create a relation between the 3 tables
ds.Relations.Add("MajSub", _
ds.Tables("MajCat").Columns("majcat"), _
ds.Tables("SubCat").Columns("majCat"))
ds.Relations.Add("SubName", _
ds.Tables("SubCat").Columns("bothcat"), _
ds.Tables("featurename").Columns("bothcat"))

' populate the treeview from the dataset
For Each rowMajCat In ds.Tables("majcat").Rows
nodeMajCat = New Microsoft.Web.UI.WebControls.TreeNode
nodeMajCat.Text = rowMajCat("majcat")
TVfeatures1.Nodes.Add(nodeMajCat)
For Each rowSubcat In rowMajCat.GetChildRows("majsub")
nodeSubcat = New Microsoft.Web.UI.WebControls.TreeNode
nodeSubcat.Text = rowSubcat("subcat")
nodeMajCat.Nodes.Add(nodeSubcat)
For Each rowfeaturename In rowSubcat.GetChildRows("subname")
nodefeaturename = New Microsoft.Web.UI.WebControls.TreeNode
nodefeaturename.Text = RTrim(rowfeaturename("featurename")) + " #" + (rowfeaturename("featurecd").ToString)
nodefeaturename.CheckBox = True
nodefeaturename.Checked = True
nodeSubcat.Nodes.Add(nodefeaturename)
Next
Next
Next
'Clean up.
ds.Dispose()
cmMajCat.Dispose()
cmSubcat.Dispose()
conc2a.Close()
conc2a.Dispose()
End Sub
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Sub appendrecord()
Dim conc2a As System.Data.SqlClient.SqlConnection
conc2a = New SqlConnection(System.Configuration.ConfigurationSettings.AppSettings("KeyConc2a"))
conc2a.Open()
Dim majNode As Microsoft.Web.UI.WebControls.TreeNode
Dim subNode As Microsoft.Web.UI.WebControls.TreeNode
Dim featureNode As Microsoft.Web.UI.WebControls.TreeNode
Dim justcd As Array
Dim thekey As String
'lblselections.Text = ""
For Each majNode In TVfeatures1.Nodes
For Each subNode In majNode.Nodes
For Each featureNode In subNode.Nodes
'''''''''''''''''''''''''''''''''''''''''''''''''''' next line sometimes is correct and sometime not
If featureNode.Checked = True Then
'lblselections.Text &= "
  • " & featureNode.Text
    justcd = featureNode.Text.Split("#")
    'justcd(1)
    ' write a record to features with info from treeview and the text of ckbxfeaturecd
    thekey = justcd(1)
    Dim cmdfeaturesInsert = New System.Data.SqlClient.SqlCommand
    cmdfeaturesInsert = New SqlClient.SqlCommand
    cmdfeaturesInsert.commandtext = "INSERT INTO features(listingid,featurecd) " & _
    "Values (@listingid,@featurecd)"
    cmdfeaturesInsert.Connection = conc2a
    cmdfeaturesInsert.Parameters.Add("@listingid", System.Data.SqlDbType.VarChar, 8).Value = mlistingid
    cmdfeaturesInsert.Parameters.Add("@featurecd", System.Data.SqlDbType.VarChar, 8).Value = thekey
    Dim x As Integer
    x = cmdfeaturesInsert.ExecuteNonQuery()

    End If
    Next
    Next
    Next
    conc2a.Close()
    End Sub

    Paul Emery
    theoakgrove@lansing.com
    the Oakgrove Computer Group, Inc.
    Grand Rapids, Michigan, USA
    1-616-456-7133
  • Reply
    Map
    View

    Click here to load this message in the networking platform