Solved

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

Posted on 2009-05-20
3
552 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

Suggested Solutions

Title # Comments Views Activity
Why does my excel data start at B1 instead of A1. 9 91
How to create an MVC5, Razor Widget 2 26
Iteration Help (Asp.net VB) 5 24
asp.net mvc 2 19
Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

765 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