|
|
 |
| ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the ASP.NET 2.0 Basics section of the Wrox p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.
|
 |

May 16th, 2007, 12:39 PM
|
|
Authorized User
|
|
Join Date: Apr 2006
Location: , , .
Posts: 56
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
dropdownlist with heading for each category
Hi, i have got a dropdownlist that is binded to a sql server database. I can populate the dropdownlist with data but i want to catoragise the list.
Can you please suggest you to do that.
HEADING1(in BOLD)
-Item1
-Item2
HEADING2(in BOLD)
-Item3
-Item4
|

May 16th, 2007, 12:43 PM
|
|
Authorized User
|
|
Join Date: Apr 2006
Location: , , .
Posts: 56
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
This is kind of my code to populate the data from the database-----
I do not know how to categorize it
SqlConnection con = new SqlConnection(System.Configuration.ConfigurationMa nager.AppSettings["strConn"].ToString());
SqlCommand sqlCommand = new SqlCommand();
sqlCommand.CommandText = @"select A1, B2 from tbl_test";
con.Open();
sqlCommand.Connection = con;
SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
M.DataSource = sqlDataReader;
M.DataTextField = "MName";
M.DataValueField = "MID";
M.DataBind();
M.Items.Insert(0, "Select ....");
sqlDataReader.Close();
con.Close();
|

May 16th, 2007, 01:42 PM
|
|
Wrox Author
Points: 12,827, Level: 49 |
|
|
Join Date: Oct 2005
Location: Akron, Ohio, USA.
Posts: 4,029
Thanks: 1
Thanked 42 Times in 42 Posts
|
|
hmm. As far as making the items bold goes, I am not a CSS Guru so I am not sure on that (I don't think you can however)**.
In so far as your binding is concerned, you have a couple of options, you can prepare your SQL Statement in such a way that your data is returned in the necessary format, e.g.
HEADING1(in BOLD)
-Item1
-Item2
HEADING2(in BOLD)
-Item3
-Item4
(this is trivial to do in SQL) and you just bind to the dropdown as you are doing above.
Secondly, you could loop through the result set and manually add the items to the dropdownlist but, if the items are not in the correct order the code you will have to write to get it in order would be lengthy (I would imagine).
All and all I suggest doing this in SQL Server.
**In the event that this CAN be done in CSS, it is going to be that you have to apply different styles to the <Option> tags, if this is the case you are going to have to populate your dropdownlist Classic ASP Style so
<select>
<%foreach(DataRow dr in dt.Rows){
if(somevalue = value)
{
%>
<option class="category"><%=dr["column"]%></option>
<%
}
else
{
%>
<option class="item"><%=dr["column"]%></option>
<%
}
<%}%>
</select>
================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
================================================== =========
Why can't Programmers, program??
http://www.codinghorror.com/blog/archives/000781.html
================================================== =========
|

May 16th, 2007, 02:53 PM
|
|
Authorized User
|
|
Join Date: Mar 2007
Location: , , .
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
You need to use the OPTGROUP in the drop down [selection]. Getting it into the dataset could be done with a UNION in the query I expect, but you'll have to work that out. Do a search on OPTGROUP and see how you get on.
|

May 16th, 2007, 05:17 PM
|
|
Authorized User
|
|
Join Date: Apr 2006
Location: , , .
Posts: 56
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I could combine the dataset using the UNION between the two select statement. But having a hard time to show the heading to categorize.
so my code --
private void BindProgramToDropDown()
{
SqlConnection con = new SqlConnection(System.Configuration.ConfigurationMa nager.AppSettings["strConn"].ToString());
SqlCommand sqlCommand = new SqlCommand();
sqlCommand.CommandText = @"Select DISTINCT tbl_P.PName AS CAMPUS, tbl_P.PID from tbl_P
UNION ALL
Select DISTINCT tbl_P.PName AS ONLINE,tbl_P.PID from tbl_P ;"
con.Open();
sqlCommand.Connection = con;
SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
P.DataSource = sqlDataReader;
P.DataTextField = "Campus";
P.DataValueField = "ProgramID";
Program.DataBind();
Program.Items.Insert(0, "Select --");
sqlDataReader.Close();
con.Close();
So I have to show two category Online and Campus under dropdownlist.
I need some help.Thank you
|

May 16th, 2007, 05:19 PM
|
|
Authorized User
|
|
Join Date: Apr 2006
Location: , , .
Posts: 56
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I cannot use manual select statement , as there are multiple list items , and it has to be dynamically generated.
Thank you
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
 |