how to fill dropdown item selectindex change

Posted by Shail12345 under ASP.NET on 11/11/2013 | Points: 10 | Views : 779 | Status : [Member] | Replies : 4
Hi All Senior Sir,
i have two dropdown
one is PropNature(Commercial,Reidentail)two field
second is propType(1bhk,2bhk,office,plot etc)
i bind both dropdownlist and data show in dropdownlist but requrement is that
if user select (Residentail)[PropNature]dropdownlist then show only 1bhk,2bhk,3bhk,4bhk,
and user select (commercial)[propnature]dropdownlist then show only office,plot,corpateoffice
I have two table is that
PropNature tableName
PID int,
PropName(Residentail,Commercial)

and second Table is
PropType TableName
PropId int,
PropName(1bhk,2bhk,Office,Plot)
plz suggest me
thanks




Responses

Posted by: Bandi on: 11/11/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
PropNature tableName
PID int Primary key,
PropName(Residentail,Commercial)

1 Residential
2 Commercial

and second Table is
PropType TableName
PropId int,
PropName(1bhk,2bhk,Office,Plot) ,
-- Add one more column to represent PropNature
PID INT references PropNature( PID)


1 1bhk 1
2 2bhk 1
3 3bhk 1
4 office 2
5 plot 2

And follow this link for population of drop downlist based on another drop down
http://www.aspdotnet-suresh.com/2010/10/how-to-populate-dropdown-based-on-other.html

Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Shail12345, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bandi on: 11/11/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
Code should as follwos:

//binding drop down list PropNature
protected void BindContrydropdown()
{
//conenction path for database
SqlConnection con = new SqlConnection(strConnection);
con.Open();
SqlCommand cmd = new SqlCommand("select * from PropNature", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
con.Close();
ddlNature.DataSource = ds;
ddlNature.DataTextField = "PropName";
ddlNature.DataValueField = "PropName";
ddlNature.DataBind();
ddlNature.Items.Insert(0, new ListItem("--Select--", "0"));
ddlType.Items.Insert(0, new ListItem("--Select--", "0"));
}

//populating PropType drop down based on PropNature value
protected void ddlNature_SelectedIndexChanged(object sender, EventArgs e)
{
string NatureID = ddlNature.SelectedValue;
SqlConnection con = new SqlConnection(strConnection);
con.Open();
SqlCommand cmd = new SqlCommand("select * from PropType where PID IN ( SELECT PID FROM PropNature WHERE PropName = '"+NatureID + "' )", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
con.Close();
ddlType.DataSource = ds;
ddlType.DataTextField = "PropName";
ddlType.DataValueField = "PropName";
ddlType.DataBind();
ddlType.Items.Insert(0, new ListItem("--Select--", "0"));
}


Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Shail12345, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Shail12345 on: 11/12/2013 [Member] Starter | Points: 25

Up
0
Down
thanks sir nice code

Shail12345, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bandi on: 11/12/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
click on "Mark as Answer "

Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Shail12345, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response