ASP.NET - how to display dropdownlist control with subtitles

Asked By saranya on 14-Nov-11 07:09 AM
Hi frndz!

     I am doing a project in asp.net2.0,c#. in my project i have used dropdownlist control. the client need was inside the dropdownlist there is subtitle.i didnt use database for this.For example:

Incense Sticks--->This is title
    -Jasmine----->Subtitle
    -Sandal------->Subtitle
Poooja items
    -Camphor
    -Rose Water

These type of model i want in dropdownlist.Thanks in advance frndz
Jitendra Faye replied to saranya on 14-Nov-11 07:11 AM

Create like this-

<


select id="myselect">

<

optgroup label="COUNTRY">

<

option label="country1">


country1


</

option>

<

option label="country2">country2</option>

</

optgroup>

<

optgroup label="STATE">

<

option label="STATE1">


STATE1


</

option>

<

option label="STATE2">STATE2</option>

</

optgroup>

</

select>



Try this and let me know.

dipa ahuja replied to saranya on 14-Nov-11 07:12 AM
Untitled document
For this purpose TreeView is used
 
Add new siteMap file in your file that is web.sitemap:
 
<?xml version="1.0" encoding="utf-8" ?>
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
 <siteMapNode url="Default.aspx" title="Home"  description="This is home page">
 <siteMapNode url="Default2.aspx" title="Child1"  description="Child1" />
 <siteMapNode url="Default3" title="Child2"  description="Chil2" />
 </siteMapNode>
</siteMap>
Now Add Tree Control + SiteMapDataSource and set the Datasource property of TreeView:
 
<asp:TreeView ID="TreeView2" runat="server" DataSourceID="SiteMapDataSource1">
</asp:TreeView>
<asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" />
 
Reena Jain replied to saranya on 14-Nov-11 07:54 AM
Hi,

using dropdownlist you can not achieve this. either you need to use treeview or site map. for above Scenario you can use multiple dropdown also

Set Visible="False" for ddl2 & 3.  In the selectedindexchanged event of ddl1, set visible = true for ddl2, and in the selectedindexchanged event of ddl2, set visible = true for ddl3.  Also, make sure AutoPostBack=true on DDLs 1 & 2 (and 3 if you so wish/need).

As for the default value, typically people add a generic "Please Select" as the first item of a ddl; you can combine that with requiredfieldvalidators, if you so wish.

Kirtan Patel replied to saranya on 14-Nov-11 10:21 PM
 <select>
<optgroup label="numbers">
  <option>One</option>
  <option>Two</option>
  <option>Three</option>
</optgroup>
 
<optgroup label="letters">
  <option>a</option>
  <option>b</option>
  <option>c</option>
</optgroup>
</select>