Hello guys, hope in your appreciated help.
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:
<asp:DropDownList ID="txt" runat="server" AutoPostBack="true" OnSelectedIndexChanged="Save_SelectedIndexChanged">
</asp:DropDownList>
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();
}
}
when I select one new value of my txtDDL fired this event:
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("<script language=javascript>\
");
sb.Append("alert("ok");
sb.Append("window.history.go(-1);\
");
sb.Append("\
</script>");
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "MyScript", sb.ToString(), false);
}
finally
{
myConnectionString.Close();
}
}
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