Click here to Skip to main content
16,012,316 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

How to display data in textboxt when you click dropdownlist.
This code only in designer, when i click dropdownlist,i will appear data and you may also can edit and update it data.


XML
<table style="width: 100%">
        <tr>
            <td align = "right" style="height: 67px">
                <asp:Label ID="LabelResp" runat="server" Text="Response Status: "
                 ></asp:Label>
            </td>
            <td style="height: 67px">
                <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True">
                </asp:DropDownList>
            </td>
        </tr>
        <tr>
            <td colspan="2" >
                <asp:TextBox ID="TextBox1" runat="server" Height="300px" Width="500px" ></asp:TextBox>
                <asp:HtmlEditorExtender ID="TextBox1_HtmlEditorExtender" runat="server"  DisplaySourceTab ="false" EnableSanitization ="false"
                    Enabled="True" TargetControlID="TextBox1">
                </asp:HtmlEditorExtender>
            </td>
        </tr>
        <tr>
            <td colspan="2" align="center">
                <br />
                <asp:Button ID="Button1" runat="server" Text="Save" />
                <asp:Label ID="lblMessage" runat="server" ForeColor="#009933"></asp:Label>
            </td>
        </tr>
    </table>



Thanks in advance.
Posted

1 solution

1.set DropDownList's attribute : AutoPostBack=true

2.add onchange event
C#
<asp:dropdownlist id="DropDownList1" onchange="change()" runat="server" autopostback="True" >

3.
C#
function change(){
document.getElementById("TextBox1").innerText="1234";
}

the previous code is client scrpit.

Server code :add SelectedIndexChanged event
C#
<asp:dropdownlist id="DropDownList1" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" runat="server" autopostback="True" >

C#
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
TextBox1.Text="1234";
}

http://msdn.microsoft.com/zh-tw/library/system.web.ui.webcontrols.listcontrol.selectedindexchanged.aspx[^]
 
Share this answer
 
v3

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