Oh if that is the case I would use an update panel. Put the second drop down in an update panel and set the asyncpostbacktrigger control to the first dropdown and the event to the selectedindexchanged event. The set the autopostback property on the first drop
down to true. Then in the selectedindexchanged event in the code behind you can populate the values of the second drop down. If you need an example let me know.
And make COMMONTrue if both male and female statuses are in common.
And make ISMALETrue and ISFEMALEFalse for male statuses.
And make ISFEMALE True and ISMALEFalse for female statuses.
**VB Code**
Protected Sub ddlSexType_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlSexType.SelectedIndexChanged
Try
Dim context As New EGrantsModel.Entities
If (ddlSexType.SelectedValue = "Female") Then
Dim femaleDataSource As Object
femaleDataSource = (From femaleDS In context.CITIZENSTATUS _
Where femaleDS.ISFEMALE = "1" And femaleDS.ISMALE = "0" AndAlso femaleDS.COMMON = "1"
Select femaleDS)
ddlCitizenStatus.DataSource = femaleDataSource
ddlCitizenStatus.DataValueField = "CITIZENSTATUSID"
ddlCitizenStatus.DataTextField = "CITIZENSTATUS"
ddlCitizenStatus.DataBind()
ElseIf (ddlSexType.SelectedValue = "Male") Then
Dim maleDataSource As Object
maleDataSource = (From femaleDS In context.CITIZENSTATUS _
Where femaleDS.ISFEMALE = "0" And femaleDS.ISMALE = "1" AndAlso femaleDS.COMMON = "1"
Select femaleDS)
ddlCitizenStatus.DataSource = maleDataSource
ddlCitizenStatus.DataValueField = "CITIZENSTATUSID"
ddlCitizenStatus.DataTextField = "CITIZENSTATUS"
ddlCitizenStatus.DataBind()
End If
Catch ex As Exception
callErrorPage(ex.Message, ex.InnerException)
End Try
End Sub
I am really new to VB, so if someone think that this a lengthy approach then kindly update me for a better approach.
Marked as answer by aazizmajid on Jul 30, 2012 01:44 AM
aazizmajid
0 Points
3 Posts
Drop-Down Cascade Issue: How to cascade two drop down
Jul 29, 2012 01:38 PM|LINK
I am trying to cascade dropdowns using ASP and VB
1st drop down --> Sex Type > Male > Female 2nd Drop Down -->Status > Orphan > Married > UnMarried > Divorced > Widow > Special Need > NormalNow,
If Male selected from 1st drop down, then select (Orphan, Special Need, Married, UnMarried, Divorced, Widow and Normal) from 2nd Drop Down
And if Female selected from 1st drop down, then select (Orphan, Special Need and Normal) from 2nd Drop Down
I am getting data of drop dwons from database using Entities;
VB Code
context As New EGrantsModel.Entities ddlSexType.DataSource = context.SEXTYPE ddlSexType.DataValueField = "SEXTYPE" ddlSexType.DataTextField = "SEXTYPE" ddlSexType.DataBind() ddlCitizenStatus.DataSource = context.CITIZENSTATUS ddlCitizenStatus.DataValueField = "CITIZENSTATUSID" ddlCitizenStatus.DataTextField = "CITIZENSTATUS" ddlCitizenStatus.DataBind()ASP Code
<div class="labelinput"> <asp:Label ID="lblSexType" CssClass="lblwidth" runat="server" Text="">Sex Type</asp:Label> <asp:DropDownList ID="ddlSexType" runat="server"/> </div> <div class="labelinput"> <asp:Label ID="lblCitizenStatus" CssClass="lblwidth" runat="server" Text="">Status</asp:Label> <asp:DropDownList ID="ddlCitizenStatus" runat="server"/> </div>Can any one guide me in this regards. Thank you
aterra
Participant
910 Points
162 Posts
Re: Drop-Down Cascade Issue: How to cascade two drop down
Jul 29, 2012 02:51 PM|LINK
Take a look at this form post it is similar to what you are trying to acomplish.
http://forums.asp.net/t/1751806.aspx/1
aazizmajid
0 Points
3 Posts
Re: Drop-Down Cascade Issue: How to cascade two drop down
Jul 29, 2012 07:57 PM|LINK
Hey aterra
Thank you for your help, but I forget to mention that I am trying to accomplish it without using jquery. Just want to accomplish in VB only.
aterra
Participant
910 Points
162 Posts
Re: Drop-Down Cascade Issue: How to cascade two drop down
Jul 29, 2012 08:07 PM|LINK
aazizmajid
0 Points
3 Posts
Re: Drop-Down Cascade Issue: How to cascade two drop down
Jul 30, 2012 01:44 AM|LINK
This is how I solved my problem
I just add three fields in my table
1- ISMALE 2- ISFEMALE 3- COMMONAnd make COMMON True if both male and female statuses are in common.
And make ISMALE True and ISFEMALE False for male statuses.
And make ISFEMALE True and ISMALE False for female statuses.
**VB Code**
Protected Sub ddlSexType_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlSexType.SelectedIndexChanged Try Dim context As New EGrantsModel.Entities If (ddlSexType.SelectedValue = "Female") Then Dim femaleDataSource As Object femaleDataSource = (From femaleDS In context.CITIZENSTATUS _ Where femaleDS.ISFEMALE = "1" And femaleDS.ISMALE = "0" AndAlso femaleDS.COMMON = "1" Select femaleDS) ddlCitizenStatus.DataSource = femaleDataSource ddlCitizenStatus.DataValueField = "CITIZENSTATUSID" ddlCitizenStatus.DataTextField = "CITIZENSTATUS" ddlCitizenStatus.DataBind() ElseIf (ddlSexType.SelectedValue = "Male") Then Dim maleDataSource As Object maleDataSource = (From femaleDS In context.CITIZENSTATUS _ Where femaleDS.ISFEMALE = "0" And femaleDS.ISMALE = "1" AndAlso femaleDS.COMMON = "1" Select femaleDS) ddlCitizenStatus.DataSource = maleDataSource ddlCitizenStatus.DataValueField = "CITIZENSTATUSID" ddlCitizenStatus.DataTextField = "CITIZENSTATUS" ddlCitizenStatus.DataBind() End If Catch ex As Exception callErrorPage(ex.Message, ex.InnerException) End Try End SubI am really new to VB, so if someone think that this a lengthy approach then kindly update me for a better approach.