It possible disable one DropDownList after changed the value in the same DropDownList?
How to intercept the change in DropDownList ?
my problem is:
I've one dropdownlist with or without selected value:
[CODE]
private void txtDDL()
{
txt.Items.Clear();
txt.Items.Add(new ListItem("------", ""));
txt.Items.Add(new ListItem("A", "A"));
txt.Items.Add(new ListItem("B", "B"));
txt.Items.Add(new ListItem("C", "C"));
txt.Items.Add(new ListItem("D", "D"));
txt.AppendDataBoundItems = true;
mySQL = "SELECT txt FROM dotable WHERE txt = ? ";
OdbcCommand objCmd =
new OdbcCommand(mySQL, myConnectionString);
objCmd.Parameters.AddWithValue("param1", dbDDL.SelectedItem.Value);
objCmd.CommandType = CommandType.Text;
objCmd.CommandText = mySQL;
try
{
myConnectionString.Open();
OdbcDataReader dr = objCmd.ExecuteReader();
while (dr.Read())
{
if (dr["txt"].ToString() != "")
{
txt.DataTextField = "txt";
txt.DataValueField = "txt";
txt.DataBind();
txt.SelectedValue = dr["txt"].ToString();
if (dr["txt"].ToString() == "A" || dr["txt"].ToString() == "B")
{
txt.Enabled = false;
}
}
}
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
finally
{
myConnectionString.Close();
}
}[/CODE]
when I select one new value of my txtDDL fired this event:
[CODE]protected void Save_SelectedIndexChanged(object sender, EventArgs e)
{
OdbcCommand cmd = new OdbcCommand("update ....", myConnectionString);
cmd.Parameters.AddWithValue("param1", txtDDL.SelectedItem.Value);
cmd.Parameters.AddWithValue("param2", DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"));
try
{
myConnectionString.Open();
cmd.ExecuteNonQuery();
cmd.Dispose();
StringBuilder sb = new StringBuilder();
sb.Append("");
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "MyScript", sb.ToString(), false);
}
finally
{
myConnectionString.Close();
}
}[/CODE]
when the event is fired and return to home page I need disable the dropDown List.
Any suggestion would be greatly appreciated
Thank you in advance
Riyaz AkhtarPosted Feb 4, 2014, 5:07 AM
Chevy Mark SunderlandPosted Feb 4, 2014, 4:19 AM
Riyaz AkhtarPosted Feb 3, 2014, 12:54 PM
Please correct me if i am wrong.
Use sb.Append("window.location.href ='home.aspx?redirect=1';"); instead sb.Append("window.history.go(-1);\n");
and read the redirect querystring in your home page. if it has value 1 make your dropdownlist disable.