dodgybouy
asked on
Bubble Event for obtaining dropdownlist index change in a formview insert template
I have a FormView "FormView1" which contains a drop down list "dropdownlist1" in the insert template. I need to be able to get the value when the selected index is changed in the drop down list. I understand this is done using bubble events. How do I do this in c#?
ASKER
This is helpful and has got me half way to solving the problem. However when I use this code the action only triggers after the command event is triggered by the template (i.e. somebody clicking the update or cancel button). what is require is for the event to trigger when the selected index changes on the drop down list.
To do this I understand you have to use a bubble event to trigger the templates command event when the selected index change event fires within the template. Do you know how to do this?
To do this I understand you have to use a bubble event to trigger the templates command event when the selected index change event fires within the template. Do you know how to do this?
where did you put the dropdownlist, insertTemplate/EditTemplat e or somewhere else? because i use formview with databound dropdownlist and i can fire selected index change event properly...
can you show us your code?
can you show us your code?
ASKER
I put the dropdownlist in an edit template,
aspx file
<asp:FormView ID="FormView1" runat="server" DataKeyNames="ID"
DataSourceID="SqlDataSourc e2" DefaultMode="Edit" Visible="False"
OnItemUpdated="FvComment_U pdated" OnItemUpdating="FvComment_ Updating" OnItemCommand="FvComment_C ommand">
<HeaderTemplate>
<strong>Comment</strong>
</HeaderTemplate>
<EditItemTemplate>
<strong>Select Comment:</strong>
<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="sqlDSGetComm ent"
DataTextField="Comment" OnSelectedIndexChanged="Dr opDownList 1_Selected IndexChang ed"
DataValueField="CommentID" SelectedValue='<%# Bind("CommentID") %>'>
</asp:DropDownList><asp:Sq lDataSourc e ID="sqlDSGetComment" runat="server" ConnectionString="<%$ ConnectionStrings:AngusCon nectionStr ing %>"
SelectCommand="spGetCommen tType" SelectCommandType="StoredP rocedure"> </asp:SqlD ataSource>
<br />
<asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update"
Text="Update" OnClientClick="return confirm('Are you sure that you want to update this comment, all current data will be lost?');" >
</asp:LinkButton>
<asp:LinkButton ID="UpdateCancelButton" runat="server" CausesValidation="False" CommandName="Cancel"
Text="Cancel">
</asp:LinkButton>
</EditItemTemplate>
Code behind file
protected void DropDownList1_SelectedInde xChanged(o bject sender, EventArgs e)
{
DropDownList ddl1 = (DropDownList)sender;
Response.Write(ddl1.Select edValue.To String());
}
aspx file
<asp:FormView ID="FormView1" runat="server" DataKeyNames="ID"
DataSourceID="SqlDataSourc
OnItemUpdated="FvComment_U
<HeaderTemplate>
<strong>Comment</strong>
</HeaderTemplate>
<EditItemTemplate>
<strong>Select Comment:</strong>
<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="sqlDSGetComm
DataTextField="Comment" OnSelectedIndexChanged="Dr
DataValueField="CommentID"
</asp:DropDownList><asp:Sq
SelectCommand="spGetCommen
<br />
<asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update"
Text="Update" OnClientClick="return confirm('Are you sure that you want to update this comment, all current data will be lost?');" >
</asp:LinkButton>
<asp:LinkButton ID="UpdateCancelButton" runat="server" CausesValidation="False" CommandName="Cancel"
Text="Cancel">
</asp:LinkButton>
</EditItemTemplate>
Code behind file
protected void DropDownList1_SelectedInde
{
DropDownList ddl1 = (DropDownList)sender;
Response.Write(ddl1.Select
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
<asp:DropDownList AutoPostBack="True" ID="DropDownList1" runat="server"
OnSelectedIndexChanged="De
<asp:ListItem>1</asp:ListI
<asp:ListItem>2</asp:ListI
</asp:DropDownList
C# event handler:
protected void DeliveryIDDropDownList_Sel
{
DropDownList ddlDel = (DropDownList)sender;
//Do stuff
}
Hope that helps