Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Bound DropDownList with ALL but NOT Using it - HOW??

Status
Not open for further replies.

net123

Programmer
Oct 18, 2002
167
US
I have a bound dropdownlist in which I would like the 'ALL' displayed on page_load. Right now, I have the code setup as a blank and it works like bringing ALL combinations. To make it easier to read for users of my application, I would like to use ALL without coding this functionality in my SQL statements.

strSQL="SELECT StateCD FROM StateCodes Order"
Cmd1=New SqlCommand(strSQL,Conn1)
Conn1.Open()
Rdr1=Cmd1.ExecuteReader()
ddlState.DataSource = Rdr1
ddlState.DataTextField = "StatusCD"
ddlState.DataBind()
ddlState.Items.Insert(0, "")
ddlState.SelectedIndex = 0
Rdr1.close()
[/red]
As you can see, I have a blank as my first index. When the SQL SELECT[/red] is run with this blank, it searches ALL combinations. But when I put ALL[/red] in:

ddlState.Items.Insert(0, "All")
[/red]
I get 0 results returned since it is looking for the word 'ALL', which of course doesn't exist.

So, I would like to know if there is a way to do this.

Your assistance will be greatly appreciated.
 
net: Played around with this a few minutes and the following page (Notepad) worked perfectly - using your code - which, by the way, looks near perfect - at least it works here.

I'll attach the page so you can test.

<%@Import Namespace = &quot;System&quot;%>
<%@Import Namespace = &quot;System.Web&quot;%>
<%@Import Namespace = &quot;System.Web.UI&quot;%>
<%@Import Namespace = &quot;System.Web.UI.WebControls&quot;%>
<%@Import Namespace = &quot;System.Web.UI.HtmlControls&quot;%>
<%@Import Namespace = &quot;System.Data&quot;%>
<%@Import Namespace = &quot;System.Data.OleDb&quot;%>
<script runat=&quot;server&quot;>
Private Sub Page_Load(sender As Object, e As EventArgs)
If Not IsPostBack Then
'open database...
Dim cmdSelect As OLEDbCommand
Dim dbconnSiteRecs As OleDbConnection = New OleDbConnection( _
&quot;Provider=Microsoft.Jet.OLEDB.4.0; &quot; & _
&quot;Data Source=&quot; & Server.MapPath(&quot;fpdb\Sites.mdb;&quot;))
cmdSelect = New OLEDbCommand(&quot;SELECT DISTINCT County FROM WebMasterSites&quot;, dbconnSiteRecs)
dbconnSiteRecs.Open()
ddCty.DataSource = cmdSelect.ExecuteReader()
ddCty.DataTextField = &quot;County&quot;
ddCty.DataBind()
ddCty.Items.Insert(0,&quot;All&quot;)
ddCty.SelectedIndex = 0
dbconnSiteRecs.Close()
End If
End Sub
</script>
<HTML>
<HEAD>
<TITLE>Test Dropdown</TITLE>
<BODY>
<form id=&quot;Form1&quot; method=&quot;post&quot; runat=&quot;server&quot;>
<asp:Dropdownlist id=&quot;ddCty&quot; runat=&quot;server&quot;/>
</form>
</BODY>
</html>

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top