Click here to Skip to main content
15,886,100 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
      {
          try
          {
              if (Label5.Text.Trim() == Label13.Text.Trim())
              {
                  DropDownList2.Enabled = true;
              }
              SqlConnection dbconn = new SqlConnection(ConfigurationManager.ConnectionStrings["UsersConnectionString"].ConnectionString);
              dbconn.Open();
              //string sqltemp = "select from Status_Remarks where OutgoingRequestID ='" + Label10.Text + "' ";
              //SqlCommand com = new SqlCommand(sqltemp, dbconn);
              string sqltemp1 = "update Status_Remarks set Div_Officer_Remarks='" + DropDownList1.Text + "'where OutgoingRequestID ='" + Label10.Text + "'";
              com = new SqlCommand(sqltemp1, dbconn);
              com.ExecuteNonQuery();
              dbconn.Close();
          }


I am using this coding to enable the Dropdownlist2, But it remains disabled, even when condition meets
Please help to solve
Posted
Comments
[no name] 13-Jun-14 8:12am    
why do you check the condition (Label5.Text.Trim() == Label13.Text.Trim()) at selectedIndexChanged event ?
[no name] 13-Jun-14 8:19am    
where did you disable it? it's not in pageload?
Debabrata_Das 13-Jun-14 11:24am    
Anup, apart from the issue you are facing, there are some other issues with your code.

As a best practice one should not write functionality within an event. In other words, you should write a separate function with the functionality and call that function from any event (SelectedIndexChanged in this case).

You should not form SQL by concatenating parameters which leads SQL Injection problem. Always use SqlParameter object to add parameters.

- DD

when you start running dropdown enabled is false it's changing in it's own selected index changed event....
 
Share this answer
 
Hello Anup,

First try to find in your code where you've set DropDownList2.Enabled = false; and then set debugger points. Then debug your code, you will come to know where/when the DropDownList control is getting disabled.

Note: Please check if you have set the property in ASPX page.

- DD
 
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