Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0ListBox InteractionListBox Interaction
Previous
 
Next
New Post
10/16/2007 12:50 PM
 



While working with various listboxes in the past, I mostly had hard-coded text & values.
Lately, I have been working with "unbound" listboxes and had data populated from a sql query & databind.
I have also am getting these listboxes to do various actions on a button click event using the:
'" + ListBox1.SelectedItem.Text + "'"

I used this method as a means to auto-populate user's multiple choices, rather than being open to interpretation by letting the user input option via a textbox.
Using this method allows for only available options to display.

Having said that, the '" + ListBox1.SelectedItem.Text + "'" method, seems to only have worked on
queries that used the method for DELETE or UPDATE methods. The issue is it is not working corrcetly with SELECT.

I used this same style of code to create the logical answer:

Me.ListBox2.Items.Clear()
Dim mySqlString As New StringBuilder()
mySqlString.Append("SELECT fieldname1")
mySqlString.Append("FROM tablename WHERE
fieldname2='" + ListBox1.SelectedItem.Text + "'")
mySqlString.Append("ORDER BY fieldname1 ASC")
Me.ListBox2.DataSource = CType(DataProvider.Instance().ExecuteSQL(mySqlString.ToString(), Nothing), IDataReader)
Me.ListBox2.DataBind()


I have been told that this code looks correct, yet it does not work correctly.
As a control to testing, I setup the same event, but replaced the '" + ListBox1.SelectedItem.Text + "' with a hard-coded value, and it works!
By doing this, I verified that the query is working correctly. Nothing changes between the two experiments other than the:

...fieldname2='" + ListBox1.SelectedItem.Text + "'")
&
...fieldname2=value")

Therfore, it seems to be an issue with the syntax.
I also tried: 
'" + ListBox1.SelectedItem.Value + "'"
'" + ListBox1.SelectedValue + "'"
And Yes, I already am using correct DataValueField name 
(which would traditionally cause listbox to be blank, but this is assigned and correct.....?)

The overall goal is to have:
1.) ListBox1 populate list. (which is working correctly)
2.) Button1, when clicked, will run the blue code above, and dynamically include ListBox1's selection into query & populateListBox2 in step #3.
3.) ListBox2 will populate list accordingly (which is not working)
4.) Repeat etc...

Currently, step #2 causes the browser to think for a second and return to same state. ListBox2 is empty. 

What syntax will I need to achieve this, so that the Listbox2 calculates the SELECT sql query using ListBox1 selected option?
And/or why wouldn't the traditional '" + ListBox1.SelectedItem.Text + "'" work?


Feedback Appreciated,

- machina12

 

 
New Post
10/16/2007 1:01 PM
 

Try this:

 

Me.ListBox2.Items.Clear()
Dim mySqlString As New StringBuilder()
mySqlString.Append("SELECT fieldname1 ")
mySqlString.Append("FROM tablename WHERE fieldname2 = @myParam ")
mySqlString.Append("ORDER BY fieldname1 ASC")

Dim myParam As SqlParameter = New SqlParameter("@myParam", SqlDbType.Nvarchar, 100)
myParam.Value = ListBox1.SelectedItem.Text


Me.ListBox2.DataSource = CType(DataProvider.Instance().ExecuteSQL(mySqlString.ToString(), myParam), IDataReader)
Me.ListBox2.DataBind()



Michael Washington
http://ADefWebserver.com
www.ADefHelpDesk.com
A Free Open Source DotNetNuke Help Desk Module
 
New Post
10/16/2007 1:37 PM
 



Genious!
It now works as intended.
I will be able to analyze SqlParameter code and now impliment accordingly into future developments.

Thanks for the timely response & taking the time to fully understand my concern.
Always very helpful.

-machina12

 
Previous
 
Next
HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0ListBox InteractionListBox Interaction


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out