Go Back  HTML Forums - Free Webmaster Forums and Help Forums > WEBSITE DEVELOPMENT > Server Side Programming > ASP and ASP.NET
User Name:
Password:
 

Reply
Thread Tools   Display Modes
  View First Unread
 
Old 10-17-2009, 01:21 PM
  #1
ngaisteve1
Member
 
ngaisteve1's Avatar
 
Join Date: Nov 2002
Location: Kuala Lumpur, Malaysia (Boleh!)
Posts: 1,943
iTrader: (0)
ngaisteve1 will become famous soon enoughngaisteve1 will become famous soon enough
Can't view multiple selected checkbox

Hi, I got a problem of viewing multiple selected checkbox. I can only single selected checkbox but not multiple selected checkbox.

Anyone here know why?

My VB.NET code (.NET 2.0):

Code:
Dim dv As New DataView

strSQL = "SELECT Causes_guid, Causes_Name FROM Causes "
dtData = clsVM.getDataTable(strSQL)
chk_NGO_Causes.DataSource = dtData
chk_NGO_Causes.DataValueField = "Causes_guid"
chk_NGO_Causes.DataTextField = "Causes_Name"
chk_NGO_Causes.DataBind()

For i As Integer = 0 To chk_NGO_Causes.Items.Count - 1
  strSQL = "SELECT * FROM membercauses WHERE member_guid = '" & Session("MemberGUID") & "' "
  dtData2 = clsVM.getDataTable(strSQL)
  For x As Integer = 0 To dtData2.Rows.Count - 1
    If chk_NGO_Causes.Items(i).Value = dtData2.Rows(x)("causes_guid").ToString Then
      chk_NGO_Causes.SelectedValue = chk_NGO_Causes.Items(i).Value
    End If
  Next
Next
__________________
My Personal Home Page - www.findingsteve.net

... with God all things are possible (Matthew 19: 26)
ngaisteve1 is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote
Old 10-19-2009, 08:30 AM
  #2
afterburn
Can't say much here
 
afterburn's Avatar
 
Join Date: May 2004
Posts: 2,832
iTrader: (0)
afterburn will become famous soon enough
you have to stop re-binding the data during postback.

if Not Page.IsPostBack then

End If
__________________
ASP.net nice bits
Code Smith rocking tool for Code Generation in any language (Written in .net)
Red Gate SQL tools for DBA
Blog Personal blog
.afterburn
afterburn is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote
Old 10-19-2009, 10:20 AM
  #3
ngaisteve1
Member
 
ngaisteve1's Avatar
 
Join Date: Nov 2002
Location: Kuala Lumpur, Malaysia (Boleh!)
Posts: 1,943
iTrader: (0)
ngaisteve1 will become famous soon enoughngaisteve1 will become famous soon enough
Thanks for the reply.

I checked my code. I did have

If Not Page.IsPostBack then

End If

When I step thru the code, I realize that, it did loop well but what happened was the later value override the previous value. That's why at the end, I will only be able to see one selected value. How do I fix this? I'm still searching.
__________________
My Personal Home Page - www.findingsteve.net

... with God all things are possible (Matthew 19: 26)
ngaisteve1 is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote
Old 10-19-2009, 11:28 AM
  #4
ngaisteve1
Member
 
ngaisteve1's Avatar
 
Join Date: Nov 2002
Location: Kuala Lumpur, Malaysia (Boleh!)
Posts: 1,943
iTrader: (0)
ngaisteve1 will become famous soon enoughngaisteve1 will become famous soon enough
Found the fix at last.

Code:
            Dim dv As New DataView

            strSQL = "SELECT Causes_guid, Causes_Name FROM Causes "
            dtData = clsVM.getDataTable(strSQL)

            dtData = clsVM.getDataTable(strSQL)

            chk_NGO_Causes.DataSource = dtData
            chk_NGO_Causes.DataValueField = "Causes_guid"
            chk_NGO_Causes.DataTextField = "Causes_Name"
            chk_NGO_Causes.DataBind()

            For i As Integer = 0 To chk_NGO_Causes.Items.Count - 1
                strSQL = "SELECT causes_guid FROM membercauses WHERE member_guid = '" & Session("MemberGUID") & "'  "
                dtData2 = clsVM.getDataTable(strSQL)

                For x As Integer = 0 To dtData2.Rows.Count - 1
                    Dim currentCheckBox As ListItem = chk_NGO_Causes.Items.FindByValue(dtData2.Rows(x)("causes_guid").ToString)
                    If Not (currentCheckBox Is Nothing) Then
                        currentCheckBox.Selected = True
                    End If
                Next
            Next
__________________
My Personal Home Page - www.findingsteve.net

... with God all things are possible (Matthew 19: 26)

Last edited by ngaisteve1 : 10-19-2009 at 11:32 AM. Reason: clean up code
ngaisteve1 is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote

Reply
KEEP TABS
SPONSORS
 
Boxedart
 
 


 
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
  
 
 
 



 
  POSTING RULES
 
 
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Thread Tools
Display Modes

Forum Jump

 

All times are GMT -5. The time now is 05:52 PM.

   

Mascot team created by Drawshop.com

Powered by vBulletin® Version 3.6.7
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.

Server Monitoring by ENIACmonitor 0.01
HTMLforums.com © Big Resources, Inc. Web Design by BoxedArt.com
vRewrite 1.5 beta SEOed URLs completed by Tech Help Forum and Chalo Na.