944,057 Members | Top Members by Rank

Ad:
  • ASP.NET Discussion Thread
  • Unsolved
  • Views: 6076
  • ASP.NET RSS
Jul 15th, 2005
0

Passing values

Expand Post »
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...
Reputation Points: 10
Solved Threads: 0
Newbie Poster
erikkl2000 is offline Offline
17 posts
since Jun 2005
Jul 15th, 2005
0

Re: Passing values

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?
Reputation Points: 11
Solved Threads: 6
Junior Poster
Letscode is offline Offline
175 posts
since Feb 2005
Jul 15th, 2005
0

Re: Passing values

' 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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
erikkl2000 is offline Offline
17 posts
since Jun 2005
Jul 15th, 2005
0

Re: Passing values

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.
Reputation Points: 11
Solved Threads: 6
Junior Poster
Letscode is offline Offline
175 posts
since Feb 2005
Jul 15th, 2005
0

Re: Passing values

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.

ASP.NET Syntax (Toggle Plain Text)
  1.  
  2. Dim Newstr As String
  3. Newstr = Listbox1.SelectedItem.Text
  4.  
  5. Dim cnn As SqlConnection
  6. Dim cnn As New SqlConnection("Data Source= DeskTop; Initial Catalog=Northwind; Trusted_Connection=Yes")
  7.  
  8. Dim cmd As SqlCommand
  9. cmd = New SqlCommand("GettingParamForDDL", cnn)
  10.  
  11. cmdTest.CommandType = Data.CommandType.StoredProcedure
  12. cmdTest.Parameters.Add(New SqlParameter("@PARMHannaMoos", SqlDbType.VarChar)).Value = Newstr
  13.  
  14. cnn.Open()
  15. Dim dreader1 As SqlDataReader
  16. dreader1 = cmd.ExecuteReader()
  17. ddl.Items.Add("SELECT A VALUE")
  18. Dim firstrowfortrack As Boolean = True
  19. While dreader1.Read()
  20. ddl.Items.Add(New ListItem(dreader1(0).ToString()))
  21. If (firstrowfortrack) Then
  22. firstrowfortrack = False
  23. End If
  24. End While
  25. dreader1.Close()
  26. 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
Reputation Points: 11
Solved Threads: 6
Junior Poster
Letscode is offline Offline
175 posts
since Feb 2005
Sep 1st, 2006
0

Re: Passing values

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)

Reputation Points: 10
Solved Threads: 0
Newbie Poster
lotusflower is offline Offline
5 posts
since Jul 2006
Jul 7th, 2009
0

Re: Passing values

Hi,

I am trying to pass this value from a drop down list
NDP Grant : National Treasury Project

As soon as i select it from my drop down list i get a message saying
~/Reports/AllPropDetailsOther.asp?PriorityProj=NDP Grant : National Treasury Project is not a valid virtual path.

I have a hyper link button with this in the navigate url section
"~/Reports/AllPropDetailsOther.asp?PriorityProj="& Eval("Expr1") &""

It works fine for the other values in my ddl. So i think it might have something to do with the :

Does anyone have some suggestions for me.

Thanks
krc
Reputation Points: 10
Solved Threads: 0
Newbie Poster
krc is offline Offline
1 posts
since Jul 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ASP.NET Forum Timeline: Update Panels & Controls
Next Thread in ASP.NET Forum Timeline: Sorting Gridview within a wizard control problem.





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC