Click here to Skip to main content
16,015,594 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
can anyone tell me that how i can bind 2 drop down ?

in my project there are 2 drop down... first is Policy type and another is Claim type....

when i select in policy type drop down then in claim type drop down there should be values related to that policy type which i filled in early web forms....

MSIL
void Connection()
      {
          string strConnection = "Data Source=NSEZ-DD4-028;Initial Catalog=Insurance;Integrated Security= SSPI";
          SqlConnection objConnection = new SqlConnection(strConnection);
          try
          {

              objConnection.Open();
              SqlCommand command = new SqlCommand();


              command.CommandText = "Select Claim_Type_Id from Claim_Type where Policy_Type_Id =" + Convert.ToString(drpClaimType.Text);
              SqlDataReader reader = command.ExecuteReader();


              command.CommandText = "insert into Claims values ('" + txtSearchForCustomer.Text + "','" + Convert.ToString(txtPolicyNumber.Text) + "','" + txtDateOfLoss.Text + "','" + Convert.ToInt32(drpPolicyType.SelectedValue) + "','" + Convert.ToInt32(drpClaimType.SelectedValue) + "','" + txtAdditionalDetails.Text + "')";



              command.Connection = objConnection;
              command.ExecuteNonQuery();
              objConnection.Close();



          }
          catch (Exception e)
          {
              // Label8.Text = "";
              if (objConnection.State == ConnectionState.Open)
              {
                  objConnection.Close();
              }

          }
      }



now what changes are to be made...i m getting very confused... :(
Posted

You need 'Cascading dropdown'. Just google for same and use the one that fits in your scenario.
 
Share this answer
 
It's not coming there.
When I'm dragging it, its not working. Will it be possible with same drop down binding ?
 
Share this answer
 
v2
Hi,

first bind the data to dropdownlist policy type and in properties give autopostback to true, and in the selected index change of policy bind the
claim type. when ur binding and writing query use this --Select Claim_Type_Id from Claim_Type where Policy_Type_Id =" + drpClaimType.selectedvalue);

it may work...
if u have any doubt let me know...

Regards,
S.Inayat Basha.
 
Share this answer
 
after doing this my page is getting refreshed, and what values i had put in various text boxes, all get removed from their....

and please also tell me that where i have to write this select query ?

it is the right place where i already written?
 
Share this answer
 
Comments
Toniyo Jackson 23-Nov-10 5:07am    
r u using ispostpack in page_load?
goelhima 23-Nov-10 5:16am    
no. i just set the property...
first in page load

if (!IsPostBack) {
fillpolicy();//this is a function to fill the details of policy type
}

//this is the fuction
private void fillcombos()
{
ddlDept.Items.Clear();
ddlDept.Items.Add(new ListItem("", ""));
DataSet deptds = new DataSet();
string strConnection = "Data Source=NSEZ-DD4-028;Initial Catalog=Insurance;Integrated Security= SSPI";
SqlConnection objConnection = new SqlConnection(strConnection);
objConnection.open();
sqldataAdaptor da =new sqldataadapter("select policy_id,Policy_name from Policy",objConnection);
da.fill(deptds)


for (i = 0; i<= deptds.Tables[0].Rows.Count - 1; i++) {
ddlpolicy.Items.Add(new ListItem(deptds.Tables[0].Rows[i]["Policy_name"], deptds.Tables[0].Rows[i]["policy_id"]));
}

deptds.Dispose();
}


protected void ddlpolicy_SelectedIndexChanged(object sender, System.EventArgs e)
{
claim();
}

private void claim()
{
ddlclaim.Items.Clear();
ddlclaim.Items.Add(new ListItem("", ""));
DataSet deptds = new DataSet();
string strConnection = "Data Source=NSEZ-DD4-028;Initial Catalog=Insurance;Integrated Security= SSPI";
SqlConnection objConnection = new SqlConnection(strConnection);
objConnection.open();
sqldataAdaptor da =new sqldataadapter("select claim_id,claim_name from claim where policy_id" + ddlpolicy.SelectedValue + "",objConnection);
da.fill(deptds)


for (i = 0; i <= deptds.Tables[0].Rows.Count - 1; i++) {
ddlclaim.Items.Add(new ListItem(deptds.Tables[0].Rows[i]["claim_name"], deptds.Tables[0].Rows[i]["claim_id"]));
}

deptds.Dispose();
}



If u have any doubt...tell me

Regards,
S.Inayat Basha.
 
Share this answer
 
v2
thnaq u soo much :0
its working :-D
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900