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.
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 SubThe sproc is this:CREATE PROCEDURE select_owner_views @ParentID bigintASBEGINSET NOCOUNT ONSELECT OwnerViews.ChildID, IMS.dbo.Login.FirstName + ' ' + IMS.dbo.Login.LastName AS LoginUserFROM OwnerViewsINNER JOIN IMS.dbo.Login ONIMS.dbo.Login.LoginID=OwnerViews.ChildIDWHERE OwnerViews.ParentID = @ParentIDORDER BY LoginUserSet NOCOUNT OFFEndGO 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] |
 |
|
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 | LoginUser10 Jon23 Tara99 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] |
 |
|
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] |
 |
|
|
|
|