You must Sign In to post a response.
  • Category: ASP.NET

    Add Text in Drop Down List

    When we have drop down list to select "add text", it should change to text box to enter. Is it possible? ASP Net 2.0 using C#?

    Please let me know.

    Thank you.
  • #312267
    u should have a textbox and a drop down..
    at the page load the visibility of the textbox should be hidden

    on the onchange event of drop down u should call this javascript function

    Eg;

    <asp:DropDownList id="ddlOutCome" runat="server" onchange="Show_TextBox()"></asp:DropDownList>

    <asp:TextBox style="DISPLAY: none" id="txtIOutCome" runat="server" MaxLength="140"></asp:TextBox>

    function Show_TextBox()
    {
    if(document.getElementById('ddlOutCome').value=="Add Text")
    {
    document.getElementById('txtOutCome').style.display='block';
    }
    else if(document.getElementById('ddlOutCome').value!="Add Text")
    {
    document.getElementById('txtOutCome').style.display='none';
    }
    }

  • #312268
    hi

    try to set visibility of the textbox on dropdownlist selected index changed event

    <table cellpadding="0" cellspacing="0" border="0" width="100%" >
    <tr>
    <td >Choose TExt:</td>
    <td align="left" valign="middle"><asp:DropDownList ID="ddlPackage" runat="server" DataTextField="Category" DataValueField="ID">
    <asp:ListItem value="0"> -- Add Text--</asp:ListItem>
    </asp:DropDownList> <asp:TextBox ID="txtCategory" runat="server" MaxLength="40" Visible="False"></asp:TextBox>
    <asp:Button ID="btnSave" runat="server" Text="SAVE" CssClass="butcolor" OnClick="btnSave_Click"/>
    <asp:Button ID="btnCancel" runat="server" Text="Cancel" CssClass="butcolor" OnClick="btnCancel_Click"/></td>
    </tr>
    </table>


    Page_Load()
    {
    if(!IsPostback())
    {
    txtCategory.visible=false;
    btnSave.visible=false;
    btnCancel.visible=false;
    }

    }

    on ddlPackage_SelectedIndexChanged()
    {
    if(ddlPackage.SelectedValue.Trim()=="0")
    {
    ddlPackage.visible=false;
    txtCategory.visible=true;
    btnSave.visible=true;
    btnCancel.visible=true;
    }
    }

    I think this'll help u

    Regards
    Raji

  • #312283
    try this
    on page_load()
    {
    textbox1.visible=false;
    btnsave.visible=false;
    btncancel.visible=false;

    }

    ddl_SlectedindexChanged()

    {

    if(ddl.selecteditem.text="add text")
    {
    textbox1.visible=true;
    btnsave.visible=true;
    btncancel.visible=true;
    }

    Regards
    Varun bansal
    Do not forget to Rate the post.....


This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.