Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Development Tools
 ASP.NET
 check box list control

Author  Topic 

jhermiz

3564 Posts

Posted - 2005-03-01 : 09:16:30
First time using it...

Thought I had it worked out...

I filled it up with this:
Private Sub LoadCheckBoxList(ByVal lngID As Long)
Dim conMyData As SqlConnection
Dim cmdSelect As SqlCommand
Dim reader As SqlDataReader
'try and make a connection
Try
conMyData = New SqlConnection(ConfigurationSettings.AppSettings("strConn"))
cmdSelect = New SqlCommand("select_owner_views", conMyData)

With cmdSelect
.CommandType = CommandType.StoredProcedure
.Parameters.Add("@ParentID", SqlDbType.Int).Value = lngID
conMyData.Open()
reader = cmdSelect.ExecuteReader
End With

With Me.chklUsers
.DataSource = reader
.DataTextField = "LoginUser" 'allow user to view login
.DataValueField = "ChildID" 'allow storage of login
.DataBind() 'bind it
End With

'catch any exceptions that might be thrown
Catch ex As Exception
Response.Write("An Error Occurred: " & ex.ToString())
'clean up and close resources
Finally
cmdSelect = Nothing
reader.Close()
conMyData.Close()
conMyData = Nothing
End Try
End Sub


The sproc is this:

CREATE PROCEDURE select_owner_views @ParentID bigint
AS
BEGIN
SET NOCOUNT ON
SELECT OwnerViews.ChildID,
IMS.dbo.Login.FirstName + ' ' + IMS.dbo.Login.LastName AS LoginUser
FROM OwnerViews
INNER JOIN IMS.dbo.Login ON
IMS.dbo.Login.LoginID=OwnerViews.ChildID
WHERE OwnerViews.ParentID = @ParentID
ORDER BY LoginUser
Set NOCOUNT OFF
End
GO


Fills up beautifully...

Now what I wanted to do just to see if I can get the DataValueField (the ID) and the DataTextField (the actual text) was:


Private Sub chklUsers_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chklUsers.SelectedIndexChanged
Dim i As Integer

For i = 0 To Me.chklUsers.Items.Count - 1
If Me.chklUsers.Items(i).Selected = True Then
Me.Label1.Text = Me.Label1.Text & Me.chklUsers.SelectedItem.Text & " " & Me.chklUsers.SelectedValue
End If
Next

End Sub
[/code]

What happens is which ever check box I check off first, the rest of the checks dont matter it always just displays the first box I select. I tried just response.writing it with the same results.

I have the checkboxlistcontrol's autopost set to True.

Am I missing anything ?




Keeping the web experience alive -- [url]http://www.web-impulse.com[/url]
Imperfection living for perfection --
[url]http://jhermiz.blogspot.com/[/url]

jhermiz

3564 Posts

Posted - 2005-03-01 : 09:18:52
Wow nevermind...must be too early...
forgot to index it:

Private Sub chklUsers_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chklUsers.SelectedIndexChanged
Dim i As Integer

For i = 0 To Me.chklUsers.Items.Count - 1
If Me.chklUsers.Items(i).Selected = True Then
Me.Label1.Text = Me.Label1.Text & Me.chklUsers.Items(i).Text & " " & Me.chklUsers.Items(i).Value
End If
Next

End Sub


Keeping the web experience alive -- [url]http://www.web-impulse.com[/url]
Imperfection living for perfection --
[url]http://jhermiz.blogspot.com/[/url]
Go to Top of Page

jhermiz

3564 Posts

Posted - 2005-03-01 : 11:28:41
Ok so I still have one more question...
lets say I run that SQL and I get:

ParentID | LoginUser
10 Jon
23 Tara
99 Brett


So in the page this displays three check boxes...I want to in the code behind default Tara's check box to true based on a variable where I have her loginID. I know thats got to be possible but I dont know if I have to loop for each one finding that one with loginID=23 or if there is a direct way.

Jon



Keeping the web experience alive -- [url]http://www.web-impulse.com[/url]
Imperfection living for perfection --
[url]http://jhermiz.blogspot.com/[/url]
Go to Top of Page

jhermiz

3564 Posts

Posted - 2005-03-01 : 13:20:48
Should I just do this:


Dim i As Integer

For i = 0 To Me.chklUsers.Items.Count - 1
If Me.chklUsers.Items(i).Value = lngLoginID Then
Me.chklUsers.Items(i).Selected = True
End If
Next i


I was hoping that I did not have to loop though.


Keeping the web experience alive -- [url]http://www.web-impulse.com[/url]
Imperfection living for perfection --
[url]http://jhermiz.blogspot.com/[/url]
Go to Top of Page
   

- Advertisement -