Hi,
I am having a 2 drop-down list in my page like 1.Location :[ ]
2.Sublocation : [ ] and
I am having 2 tables in my database like Location_Lookup and Sublocation_Lookup,
in Location_Lookup having columns like 'LocationID' 'Location' and
in Sublocation_Lookup havin columns like 'SublocationID' 'LocationID' and 'Sublocation'.
Then I have created a stored Procedure to fetch the sublocation using the LocationID
like
create procedure PopSublocation @location int as
begin
Select Sublocation from Sublocation_LookUp where LocationID = @location
now for fetching the location items to the Location dropdown list i have written the code like..
protected void LocationBind()
{
SqlConnection conn = new SqlConnection(connstr);
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "Location";
conn.Open();
SqlDataReader reader = cmd.ExecuteReader();
ddlLocation.DataSource = reader;
ddlLocation.DataTextField = "Location";
ddlLocation.DataValueField = "LocationID";
ddlLocation.DataBind();
ddlLocation.Items.Insert(0, new ListItem("Select", "-1"));
conn.Close();
reader.Close();
}
Here i am using stored procedure for getting locationID and Location and in the program for ddlLocation.DataValueField= "LocationID" i am passing.
Now for fetching the related sublocation list in the Sublocation:[ ] dropdown i am writting the code in the "protected void ddlLocation_SelectedIndexChanged(object sender, EventArgs e)" and the code is
protected void ddlLocation_SelectedIndexChanged(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(connstr);
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "PopSublocation";
cmd.Parameters.AddWithValue("@location",ddlLocation.SelectedItem.Value);
ddlSublocation.Items.Insert(0, new ListItem("Select", "-1"));
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
ddlSublocation.DataSource = ds;
ddlSublocation.DataTextField = "Sublocation";
ddlSublocation.DataValueField = "SublocationID";
ddlSublocation.DataBind();
}
Here i am passing the parameter of LocationID,
but here my problem is I am not getting the sublocation details in the Sublocation dropdown list.. please help me out for this... thanks