Solved

Select drop down list value based on selection in pop up page

Posted on 2009-05-20
3
549 Views
Last Modified: 2012-05-07
I have a page that contains a drop down list of values.
Next to the drop down, I have an clickable image icon that pops up a new window that allows the user to search and select for a value.

When the user clicks on that value in the pop up window, the id is then returned to the parent page.
How can I set the selected value of the drop down with the value that was selected on the popup page?
page1.aspx

'Need to set the selected value of this drop down

'based on what the user selects in the pop up window

<asp:DropDownList ID="DropDownList1" runat="server">

</asp:DropDownList>
 

<input type="text" name="CustomerID" value  "" />                                                        

                                                        <img alt="" src="icon_preview.gif" onclick='targetitem = document.forms[0].CustomerID;dataitem = window.open("CustomerLookup.aspx", "dataitem", "toolbar=no,menubar=no,width=550,height=500"); dataitem.targetitem = targetitem' />
 

Popup page
 

    <script type="text/javascript"> 

    function select_item(item)     {

        targetitem.value = item;

        top.close();

        return false;

    }

    </script>
 

This is actually in a grid

                        <itemtemplate>

                            <a href="" onclick='return select_item("<%#Eval("CustomerID")%>")'> <%#Eval("FirstName")%> <%#Eval("LastName")%></a>

                        </itemtemplate>

Open in new window

0
Comment
Question by:JRockFL
  • 2
3 Comments
 
LVL 16

Expert Comment

by:Steve Krile
Comment Utility
Sorry for the misdirection here, but is this an Ajax enabled application.  If so, sounds like what you really could use is a Modal Popup and Update panel.  If you respond back saying, "Yeah, I could use Ajax", I'll hook you up with a pretty simple way of getting what you want here.
0
 
LVL 8

Author Comment

by:JRockFL
Comment Utility
Yeah I could use Ajax
:)
0
 
LVL 16

Accepted Solution

by:
Steve Krile earned 500 total points
Comment Utility
Sweet.  So, here is how I'd do what you are trying to accomplish - please not that a lot of the code below would need to be cleaned up for it to "work", things like data connections and page configurations to properly reference the Ajax toolkit.

.aspx Page:

          <asp:UpdatePanel runat="server" ID="MainContent" UpdateMode="Conditional">
              <Triggers>
                  <asp:AsyncPostBackTrigger ControlID="MyGrid" EventName="SelectedIndexChanged"
              </Triggers>
              <ContentTemplate>
                  <asp:Label runat="server" ID="SelectedID" />
                <asp:DropDownList runat="server" ID="MyList" >
                      <asp:ListItem Text="val1" Value="0" />
                      <asp:ListItem Text="val2" Value="1" />
                  </asp:DropDownList>
                  <asp:ImageButton runat="server" ID="ModalShow" ImageUrl="~/images/myimagebutton.gif" />
                  <asp:Panel runat="server" ID="MyModal" Style="display:none;">
                      <asp:SqlDataSource ID="MyGridData" Runat="server" />
                      <asp:GridView ID="MyGrid" runat="server"  
                          DataKeyNames="MyDataIDValueName"
                          DataSourceID="MyGridData"
                          OnSelectedIndexChanged="MyGrid_Selected" />
                      <asp:Button runat="server" ID="CloseModal" Text="Cancel" />
                  </asp:Panel>
                  <cc1:ModalPopupExtender runat="server" ID="MyModalExtender"
                      PopupControlID="MyModal" TargetControlID="ModalShow"
                      CancelControlID="CloseModal" />
              </ContentTemplate>
          </asp:UpdatePanel>



.aspx.vb page:


    Protected Sub MyGrid_Selected(ByVal sender As Object, ByVal e As EventArgs) Handles MyGrid.SelectedIndexChanged
        Dim MyID As Integer = CType(MyGrid.SelectedDataKey.Value, Integer)
        SelectedID.Text = MyID.ToString()
        MyModalExtender.Hide()
    End Sub
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

771 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

11 Experts available now in Live!

Get 1:1 Help Now