p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


Go Back   p2p.wrox.com Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
I forgot my password Register Now
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 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.

Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old May 16th, 2007, 12:39 PM
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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #2 (permalink)  
Old May 16th, 2007, 12:43 PM
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();

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #3 (permalink)  
Old May 16th, 2007, 01:42 PM
Wrox Author
Points: 12,827, Level: 49
Points: 12,827, Level: 49 Points: 12,827, Level: 49 Points: 12,827, Level: 49
Activity: 15%
Activity: 15% Activity: 15% Activity: 15%
 
Join Date: Oct 2005
Location: Akron, Ohio, USA.
Posts: 4,029
Thanks: 1
Thanked 42 Times in 42 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
================================================== =========
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #4 (permalink)  
Old May 16th, 2007, 02:53 PM
Authorized User
Points: 32, Level: 1
Points: 32, Level: 1 Points: 32, Level: 1 Points: 32, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #5 (permalink)  
Old May 16th, 2007, 05: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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #6 (permalink)  
Old May 16th, 2007, 05: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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
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

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off
Forum Jump

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 09: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 05:22 AM



All times are GMT -4. The time now is 05:34 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
© 2008 Wiley Publishing, Inc