RSS Forums RSS
Please support our ASP.NET advertiser: Lunarpages ASP Web Hosting
Views: 4994 | Replies: 5
Reply
Join Date: Jun 2005
Posts: 17
Reputation: erikkl2000 is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
erikkl2000 erikkl2000 is offline Offline
Newbie Poster

Passing values

  #1  
Jul 15th, 2005
Could some one please help me with the understanding how to pass the values to a drop downlist?

What i am tring to do is pass a parameter (@Likethis) from a selected item in a list box or a dropdown to a dropdown or a list box. I am assuming the i will have to attach the @Parameter to the selected item some how and in turn this will set off a stored procedured that will populate the dropdown,..

Please Help,
Erik...
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Feb 2005
Posts: 175
Reputation: Letscode is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 5
Letscode's Avatar
Letscode Letscode is offline Offline
Junior Poster

Re: Passing values

  #2  
Jul 15th, 2005
Hey Erik,
Can you be elaborative in what you need?
You told you need to pass the values to a drop downlist?

Whats a SP doing in that?

Can you explain us what you really want?
Save White Tiger
Reply With Quote  
Join Date: Jun 2005
Posts: 17
Reputation: erikkl2000 is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
erikkl2000 erikkl2000 is offline Offline
Newbie Poster

Re: Passing values

  #3  
Jul 15th, 2005
' Hello and thank you for your help,

'I am hoping to assoiate each itemsvalue with a (@Parm) for a stores 'procedure, so that i can populate a ddl.

' Any help at all is awsome!

' Erik....

My code.... This is as far as i could get, and i am not sure if this is even
'close, its something that i have been working with for a day or so.


Public Class TestTwo
Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

End Sub
Protected WithEvents ListBox1 As System.Web.UI.WebControls.ListBox
Protected WithEvents ddl As System.Web.UI.WebControls.DropDownList

'NOTE: The following placeholder declaration is required by the Web Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here

'
Dim cnn As New SqlConnection("data source =desktop; initial catalog= northwind;trusted_connection=yes")
cnn.Open()
'
'You can modify it to

Dim da As New SqlDataAdapter("select * from customers", cnn)
Dim ds As New DataSet
da.Fill(ds, "Test")
'
ListBox1.DataSource = ds.Tables("Test")
ListBox1.DataValueField = "ContactName"
ListBox1.DataTextField = "ContactName"
ListBox1.DataBind()

End Sub

Private Sub dl_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
'
If ListBox1.SelectedValue = "Hanna Moos" Then
ddl.DataSource = GetStuffForDDL("PrAmNaMe")
Else
ddl.Visible = False
End If
End Sub



Function GetStuffForDDL(ByVal PrAmNaMe As String) As SqlDataReader
'
'Begin The Madness
'
Dim cnn As New SqlConnection("Data Source= DeskTop; Initial Catalog=Northwind; Trusted_Connection=Yes")
Dim Mycmd As New SqlCommand("GettingParamForDDL", cnn)
'
Dim PARMHannaMoos As String = "Hanna Moos"
'
Dim PramHannaMoos As New SqlParameter("@PARMHannaMoos", SqlDbType.VarChar, 50)
PramHannaMoos.Value = PARMHannaMoos
Mycmd.Parameters.Add(PramHannaMoos)
'
Mycmd.CommandType = CommandType.StoredProcedure
'
cnn.Open()
Dim Result As SqlDataReader = Mycmd.ExecuteReader(CommandBehavior.CloseConnection)
Return Result
cnn.Close()
Result.Close()
'
'End The Madness
'
End Function
End Class
Reply With Quote  
Join Date: Feb 2005
Posts: 175
Reputation: Letscode is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 5
Letscode's Avatar
Letscode Letscode is offline Offline
Junior Poster

Re: Passing values

  #4  
Jul 15th, 2005
Oh,So this is what you want.
You have a listbox and a drop downbox.

The user selects an option from the list box and based on the values selected from the list box ,the drop downlist has to be populated.

You need to know
how to associate the values from the listbox as a parameter to the SP for populating the DDL.
Save White Tiger
Reply With Quote  
Join Date: Feb 2005
Posts: 175
Reputation: Letscode is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 5
Letscode's Avatar
Letscode Letscode is offline Offline
Junior Poster

Re: Passing values

  #5  
Jul 15th, 2005
This is what you have to do..
Do one step at a time.

1.Select the listbox and SET THE AUTO POSTBACK PROPERTY TO TRUE.
This will trigger an event and everytime you make a different selection in the Listbox and LISTBOX.SelectedIndexChanged event will be triggered.

2.In the page load,do what you are doing.Dont change anything

3.Now double click the Listbox and Enter these codes.

Set the Listbox1.SelectedItem.Text to a String.

Dim Newstr As String
Newstr = Listbox1.SelectedItem.Text 

Dim cnn As SqlConnection
Dim cnn As New SqlConnection("Data Source= DeskTop; Initial Catalog=Northwind; Trusted_Connection=Yes")

Dim cmd As SqlCommand
cmd = New SqlCommand("GettingParamForDDL", cnn)

cmdTest.CommandType = Data.CommandType.StoredProcedure
cmdTest.Parameters.Add(New SqlParameter("@PARMHannaMoos", SqlDbType.VarChar)).Value = Newstr
  
cnn.Open()
Dim dreader1 As SqlDataReader
dreader1 = cmd.ExecuteReader()
ddl.Items.Add("SELECT A VALUE")
Dim firstrowfortrack As Boolean = True
While dreader1.Read()
                    ddl.Items.Add(New ListItem(dreader1(0).ToString()))
                    If (firstrowfortrack) Then
                        firstrowfortrack = False
                    End If
End While
dreader1.Close()
cnn.Close()


Remember.I'm just typing this code..I havent tested it.

I think this is what you need.

If you get some errors,then post the error.We should be able to help you.

Hope it helps
Save White Tiger
Reply With Quote  
Join Date: Jul 2006
Posts: 5
Reputation: lotusflower is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
lotusflower's Avatar
lotusflower lotusflower is offline Offline
Newbie Poster

Re: Passing values

  #6  
Sep 1st, 2006
Hello Letscode,

I need some help with some coding for passing two parameters, one areader and the other a listbox to a function, that will take these values and then add the values from the reader to the listbox. The code works inside a button click sub, but I have the need to pass to a function, which can be accessed by two different button clicks.

The code inside the sub which works now is:

How should the values be passed to the function? Can I pass a reader as an object and a listbox as an object or should it be a string which will be parsed in the function? Thanks for your help.
While myReader.Read()
SitesSelected(myReader, ListBox.SelectedValue.ToString.Trim) ListBox.Items.Add(myReader.GetValue(0))
End While
Sub SitesSelected(ByVal myreader AsObject, ByVal listboxvalue AsString)

Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

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

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 12:49 pm.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC