Solved

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

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

831 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