TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Chevy Mark Sunderland
NA
188
167.3k
[C# net4] DropDownList disabled after change value
Feb 3 2014 10:52 AM
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:
[CODE] <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();
}
}[/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("<script language=javascript>\n");
sb.Append("alert("ok");
sb.Append("window.history.go(-1);\n");
sb.Append("\n</script>");
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
Reply
Answers (
3
)
Auto login to a different website
Store Procedure not Return calculated result