Sunday, March 11, 2012

How can I dynamicly insert text between div tags based on a selection in a drop down list.

not sure what you mean, 'between tags'. Do you mean as innerHTML between a <div> and a </div> ? if so, then the easiest way is to just give your div an id, and roll with it thusly:

<div id='msg'></div>

(in your event handler): $get('msg').innerHTML = // the text you want to display


I think this is what want

<asp:DropDownListID="ddlTest" AutoPostBack="true"OnSelectedIndexChanged="UpdateLabel" runat="server">
<asp:ListItemText="Item 1"Value="Item 1"Selected="true"/>
<asp:ListItemText="Item 2"Value="Item 2"Selected="false"/>
</asp:DropDownList>

<asp:UpdatePanelID="Div_UpdatePanel"UpdateMode="Conditional"runat="server">
<Triggers>
<asp:AsyncPostBackTriggerControlID="ddlTest"EventName="SelectedIndexChanged"/>
</Triggers>
<ContentTemplate>
<asp:LabelID="lblTest"runat="sever"/>
</ContentTemplate>
</asp:UpdatePanel>

C#

protected

void UpdateLabel(object sender,EventArgs e)
{
this.lblTest.Text =this.ddlTest.SelectedValue;
}

No comments:

Post a Comment