Click here to Skip to main content
15,900,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to enable( Reason:Dropdownlist )when date is put in text box present above the drop down list .kindly post the code if u know
Posted

One approach would be to use the textchanged event[^] of the textbox and check if the user has entered a valid date using datetime-tryparse[^] method. Then enable the dropdownlist.
You can enable the dropdownlist by using the Enabled property[^]
ex: yourDropdownID.Enabled = "True";
 
Share this answer
 
Set Autopostback property of textbox true

C#
protected void TextBox1_TextChanged(object sender, EventArgs e)
{
   DateTime date1;
   if (DateTime.TryParse(dateString, out dateValue))
        dropdownlist1.Enabled=true;
   else
        dropdownlist1.Enabled=false;
}
 
Share this answer
 
v3
Default.aspx page Code.

XML
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="page2.aspx.cs" Inherits="Default.aspx" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>DropDown Demo with Textbox</title>

</head>
<body>
    <form id="form1" runat="server">
    <div>
    <asp:DropDownList ID="DropDownList1" style="Width:120px" runat="server"
            Enabled="False">
    <asp:ListItem>santosh_k</asp:ListItem>
    <asp:ListItem>Amit_K</asp:ListItem>
    </asp:DropDownList>
    </div>
    <div>Choose Date:
    <asp:TextBox ID="txtDate"  style="margin-top:50px"  runat="server"></asp:TextBox>
        <asp:Calendar ID="Calendar1" runat="server"
            onselectionchanged="Calendar1_SelectionChanged1"></asp:Calendar>
    </div>
    <div>

    </div>
    </form>
</body>
</html>



Default.aspx.cs Code Behind
C#
protected void Calendar1_SelectionChanged1(object sender, EventArgs e)
   {
       txtDate.Text = Calendar1.SelectedDate.ToString();
       DropDownList1.Enabled = true;
   }
 
Share this answer
 
v2

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