Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old May 16th, 2007, 11:39 AM
Authorized User
 
Join Date: Apr 2006
Location: , , .
Posts: 56
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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

Reply With Quote
  #2 (permalink)  
Old May 16th, 2007, 11:43 AM
Authorized User
 
Join Date: Apr 2006
Location: , , .
Posts: 56
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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();

Reply With Quote
  #3 (permalink)  
Old May 16th, 2007, 12:42 PM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

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
================================================== =========
Reply With Quote
  #4 (permalink)  
Old May 16th, 2007, 01:53 PM
Authorized User
 
Join Date: Mar 2007
Location: , , .
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.
Reply With Quote
  #5 (permalink)  
Old May 16th, 2007, 04:17 PM
Authorized User
 
Join Date: Apr 2006
Location: , , .
Posts: 56
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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

Reply With Quote
  #6 (permalink)  
Old May 16th, 2007, 04:19 PM
Authorized User
 
Join Date: Apr 2006
Location: , , .
Posts: 56
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I cannot use manual select statement , as there are multiple list items , and it has to be dynamically generated.

Thank you

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
display no heading if null oleafo ASP.NET 1.0 and 1.1 Basics 1 January 8th, 2007 06:23 PM
Inserting a heading only in only the first element stekker XSLT 2 September 28th, 2006 08:06 AM
Cannot Modigy Heading wongcalvin Beginning PHP 1 December 12th, 2004 11:05 PM
Need help with creating a Parent Category seanmayhew BOOK: ASP.NET Website Programming Problem-Design-Solution 2 November 13th, 2004 06:20 PM
Finding a heading in a word document nesplb Pro VB 6 1 August 18th, 2003 04:22 AM



All times are GMT -4. The time now is 06:39 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.