hi friends,
i need your help in my project. i need to group my dropdownlist data.
can anyone help me to get "optgroup" functioning in asp.net 1.0 using vb.net

Recommended Answers

All 13 Replies

Member Avatar for rajarajan2017
<select>
<optgroup label="Swedish Cars">
<option value ="volvo">Volvo</option>
<option value ="saab">Saab</option>
</optgroup>
<optgroup label="German Cars">
<option value ="mercedes">Mercedes</option>
<option value ="audi">Audi</option>
</optgroup>
</select>

Please execute it and check for the output. I hope it will help you with optgroup, if yes add to reputation and mark it as solved.

hi
thanks rajarajan
but i know this code. i am searching to do same with asp.net control. do u know it! then plz help.
Note:I am filling that DropDownList from DB

Member Avatar for rajarajan2017

If you need help about optgroup tag means please visit this link:
http://www.devguru.com/technologies/xhtml/7758.asp

If you need help from any asp list control means plz reply to this thread, I will help out U and also from our forum members.

Member Avatar for rajarajan2017

Hi,

Place two dropdownlist boxes and a label in designer. Write the coding as shown below. Just you need to change the item from the ddlcompany and It will automatically calculated and show the output as you need.

<asp:DropDownList runat="server" ID="ddlCompany" AutoPostBack ="true" /><br />
    <asp:DropDownList runat="server" ID="ddlProduct"  AutoPostBack ="true" /><br />
    <asp:Label ID="lbltest" runat="server" /><asp:DropDownList runat="server" ID="ddlCompany" AutoPostBack ="true" /><br />
    <asp:DropDownList runat="server" ID="ddlProduct"  AutoPostBack ="true" /><br />
    <asp:Label ID="lbltest" runat="server" />
Protected Sub ddlCompany_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlCompany.SelectedIndexChanged
        If ddlCompany.SelectedIndex > 0 Then
            lbltest.Text = ddlCompany.Items.Item(ddlCompany.SelectedIndex).Text & ","
            lbltest.Text &= "Your price for a " & ddlProduct.Items.Item(ddlCompany.SelectedIndex).Text & "is "
            lbltest.Text &= ddlProduct.Items.Item(ddlCompany.SelectedIndex).Value * (1 + ddlCompany.Items.Item(ddlCompany.SelectedIndex).Value)
            ddlProduct.SelectedIndex = ddlCompany.SelectedIndex
        Else
            lbltest.Text = ""
        End If
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If IsPostBack = False Then
            ddlCompany.Items.Add(New ListItem("Please Select..."))
            ddlCompany.Items.Add(New ListItem("ABC Company", "0.15"))
            ddlCompany.Items.Add(New ListItem("XYZ Inc", "0.05"))
            ddlCompany.Items.Add(New ListItem("Testing Corp", "0.20"))
            ddlCompany.Items.Add(New ListItem("Retail Sales", "0.40"))

            ddlProduct.Items.Add(New ListItem("Please Select..."))
            ddlProduct.Items.Add(New ListItem("Skateboard", "250"))
            ddlProduct.Items.Add(New ListItem("Surfboard", "598"))
            ddlProduct.Items.Add(New ListItem("Wakeboard", "459"))
            ddlProduct.Items.Add(New ListItem("Wake Skate", "125"))
        End If
    End

Please execute it and you will get the idea about the DROPDOWNLIST control in asp.net
This code was already replied to the thread named DropDownLists. Also check it there.

If this post helped you, please add it to my reputation and mark the thread as solved.

Hey thats not what i am asking

Member Avatar for rajarajan2017

Then Plz tell me exactly what you are expecting? mention the control name pa.

<select>
<optgroup label="Swedish Cars">
<option value ="volvo">Volvo</option>
<option value ="saab">Saab</option>
</optgroup>
<optgroup label="German Cars">
<option value ="mercedes">Mercedes</option>
<option value ="audi">Audi</option>
</optgroup>
</select>

Please execute it and check for the output. I hope it will help you with optgroup, if yes add to reputation and mark it as solved.

Hi , thanks for ur reply. This is what i want exact. but the problem is i am feeling this combo from db tbl. so for ex. i have 100 cityes. i want to gropu them like "IT-Cityes"
Or "Metro-Cityes" like wise. are you getting me or i made things more complex. ?
plz reply asap. thanks again.

Member Avatar for rajarajan2017

Sorry to ask you again, Tell me am I right or not?

You are having 100 cities in database, Right! (as per your example)
You want to load it in optgroup control, Right!
Are you going to use optgroup control?
Reply asap.

hi thanks for your reply and sorry for late reply. i was busy in other stuff.
actualy i only know abt filling cbos from db. when i need to sort my cbos then i
just right click on a web page having group combo. where i found "optgroup".
can i plz guid me..! i will be very thankful to you for that.

Its like following....

<SELECT id="city" name="CITY" class="">
												<option value="-1" SELECTED>Select</option>
												<optgroup value="-1" STYLE="BACKGROUND:#D0E0F1;COLOR:#000" label="-----Top Metropolitan Cities-----"></optgroup><option value="2">Ahmedabad</option>
												<option value="3">Bengaluru / Bangalore</option>
												<option value="4">Chandigarh</option>
												<option value="5">Chennai</option>
												<option value="6">Delhi</option>
												<option value="7">Gurgaon</option>
												<option value="8">Hyderabad / Secunderabad</option>
												<option value="9">Kolkata</option>
												<option value="10">Mumbai</option>
												<option value="11">Noida</option>
												<option value="12">Pune</option>
												<optgroup value="-1" STYLE="BACKGROUND:#D0E0F1;COLOR:#000" label="-----Andhra Pradesh-----"></optgroup><option value="14">Anantapur</option>
												<option value="15">Guntakal</option>
												<option value="16">Guntur</option>
												<option value="17">Hyderabad / Secunderabad</option>
												<option value="18">Kakinada</option>
												<option value="19">Kurnool</option>
												<option value="20">Nellore</option>
												<option value="21">Nizamabad</option>
												<option value="22">Rajahmundry</option>
												<option value="24">Tirupati</option>
												<option value="25">Vijayawada</option>
												<option value="26">Visakhapatnam</option>
												<option value="27">Warangal</option>
												<option value="28">Andhra Pradesh - Other</option>
												<optgroup value="-1" STYLE="BACKGROUND:#D0E0F1;COLOR:#000" label="-----Arunachal Pradesh-----"></optgroup><option value="30">Itanagar</option>
												<option value="31">Arunachal Pradesh - Other</option>
												<optgroup value="-1" STYLE="BACKGROUND:#D0E0F1;COLOR:#000" label="-----Assam-----"></optgroup><option value="33">Guwahati</option>
												<option value="34">Silchar</option>
												<option value="35">Assam - Other</option>
												<optgroup value="-1" STYLE="BACKGROUND:#D0E0F1;COLOR:#000" label="-----Bihar-----"></optgroup><option value="37">Bahgalpur</option>
												<option value="38">Patna</option>
												<option value="39">Bihar - Other</option>
												<option value="87">Jammu</option>
												<option value="88">Srinagar</option>
												<option value="89">Jammu and Kashmir - Other</option>
												<optgroup value="-1" STYLE="BACKGROUND:#D0E0F1;COLOR:#000" label="-----Jharkhand-----"></optgroup><option value="91">Bokaro</option>
												<option value="92">Dhanbad</option>
												<option value="93">Jamshedpur</option>
												<option value="94">Ranchi</option>
												<option value="95">Jharkhand - Other</option>
												<optgroup value="-1" STYLE="BACKGROUND:#D0E0F1;COLOR:#000" label="-----Karnataka-----"></optgroup><option value="97">Bengaluru 
													/ Bangalore</option>
												<option value="98">Belgaum</option>
												<option value="99">Bellary</option>
												<option value="100">Bidar</option>
												<option value="101">Dharwad</option>
												<option value="102">Gulbarga</option>
												<option value="103">Hubli</option>
												<option value="104">Kolar</option>
												<option value="105">Mangalore</option>
												<option value="106">Mysoru / Mysore</option>
												<option value="107">Karnataka - Other</option>

And so on.... :(

Member Avatar for rajarajan2017

Just you need to group the items, Right!. Better you place more controls to differentiate them. For example:

Categories : load the group names into the categories DropDownlist

SubCategories (or) Items: load the items which is relevant to the category selecting above from dropdownlist at runtime.

Would you get me? and one more thing still i want to know exactly which control you are using?

I think you are in online, tell me asap

hi 10x for rply.
i am using Asp.Net Dropdown list control.
The solution u provide may be good for solving my problem.
but i dont want that type of solution. i need same as the "optgroup" o/p.
Plz help anyone

hi 10x for rply.
i am using Asp.Net Dropdown list control.
The solution u provide may be good for solving my problem.
but i dont want that type of solution. i need same as the "optgroup" o/p.
Plz help anyone

Here is an implementation of a DropDownList and also of a ListBox:
http://www.codeplex.com/SharpPieces/

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.