-
1
- #1
I have a web form with a dropdown list bounded to a data source. This page is a search page that displays the results in a datagrid. I would like the dropdown list defaulted to one of the values of the database, but also in the list, I would like the value of 'ALL' to be in there. I seem to have figured out the code as follows.
So far I have this and I can't seem to get around it:
strSQL="SELECT CodeName FROM dbo.Codes Order By CodeID"
Cmd1=New SqlCommand(strSQL,Conn1)
Conn1.Open()
Rdr1=Cmd1.ExecuteReader()
ddlCode.DataSource = Rdr1
ddlCode.DataTextField = "CodeName"
ddlCode.DataBind()
ddlCode.Items.Insert(3, "All"
ddlCode.SelectedIndex = 0
Rdr1.close()
[/blue]
My ddl, on page_load should look something like this:
Name1 <-- default
Name2
Name3
All
[/blue]
The ddl looks fine with the above code, but how can I implement this logic into the SQL SELECT statement?
Greatly appreciate any help.
So far I have this and I can't seem to get around it:
strSQL="SELECT CodeName FROM dbo.Codes Order By CodeID"
Cmd1=New SqlCommand(strSQL,Conn1)
Conn1.Open()
Rdr1=Cmd1.ExecuteReader()
ddlCode.DataSource = Rdr1
ddlCode.DataTextField = "CodeName"
ddlCode.DataBind()
ddlCode.Items.Insert(3, "All"
ddlCode.SelectedIndex = 0
Rdr1.close()
[/blue]
My ddl, on page_load should look something like this:
Name1 <-- default
Name2
Name3
All
[/blue]
The ddl looks fine with the above code, but how can I implement this logic into the SQL SELECT statement?
Greatly appreciate any help.