Solved

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

Posted on 2009-05-20
3
554 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
ID: 24435499
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
ID: 24435523
Yeah I could use Ajax
:)
0
 
LVL 16

Accepted Solution

by:
Steve Krile earned 500 total points
ID: 24435671
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

726 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