Solved

Bubble Event for obtaining dropdownlist index change in a formview insert template

Posted on 2006-10-20
5
516 Views
Last Modified: 2012-08-14
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#?
0
Comment
Question by:dodgybouy
  • 3
  • 2
5 Comments
 
LVL 7

Expert Comment

by:here4u247
ID: 17772370
you set the selected indexchanged event to the dropdown which calls an event handler everytime the selection change i.e.

                 <asp:DropDownList AutoPostBack="True" ID="DropDownList1" runat="server"
                         OnSelectedIndexChanged="DeliveryIDDropDownList_SelectedIndexChanged">
                         <asp:ListItem>1</asp:ListItem>
                         <asp:ListItem>2</asp:ListItem>
                    </asp:DropDownList

C# event handler:


    protected void DeliveryIDDropDownList_SelectedIndexChanged(object sender, EventArgs e)
    {
        DropDownList ddlDel = (DropDownList)sender;
//Do stuff
    }

Hope that helps
0
 

Author Comment

by:dodgybouy
ID: 17773438
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?
0
 
LVL 7

Expert Comment

by:here4u247
ID: 17774097
where did you put the dropdownlist, insertTemplate/EditTemplate 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?
0
 

Author Comment

by:dodgybouy
ID: 17774131
I put the dropdownlist in an edit template,

aspx file

<asp:FormView ID="FormView1" runat="server" DataKeyNames="ID"
        DataSourceID="SqlDataSource2" DefaultMode="Edit" Visible="False"
        OnItemUpdated="FvComment_Updated" OnItemUpdating="FvComment_Updating" OnItemCommand="FvComment_Command">
            <HeaderTemplate>
                <strong>Comment</strong>
            </HeaderTemplate>
            <EditItemTemplate>
                <strong>Select Comment:</strong>
                <asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="sqlDSGetComment"
                    DataTextField="Comment"  OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged"
                    DataValueField="CommentID" SelectedValue='<%# Bind("CommentID") %>'>
                </asp:DropDownList><asp:SqlDataSource ID="sqlDSGetComment" runat="server" ConnectionString="<%$ ConnectionStrings:AngusConnectionString %>"
                    SelectCommand="spGetCommentType" SelectCommandType="StoredProcedure"></asp:SqlDataSource>
                <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_SelectedIndexChanged(object sender, EventArgs e)
        {
            DropDownList ddl1 = (DropDownList)sender;

            Response.Write(ddl1.SelectedValue.ToString());
        }
0
 
LVL 7

Accepted Solution

by:
here4u247 earned 500 total points
ID: 17774268
ahaa i see, what you need is AutoPostBack="True" i.e.

<asp:DropDownList ID="DropDownList1" AutoPostBack="True"   runat="server" DataSourceID="sqlDSGetComment"
                    DataTextField="Comment"  OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged"
                    DataValueField="CommentID" SelectedValue='<%# Bind("CommentID") %>'>

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now