?
Solved

two DDL -follow the leader

Posted on 2005-03-30
8
Medium Priority
?
315 Views
Last Modified: 2011-10-03
Hi,

Two drop down list,

ddloperatorid-contains id
ddloperatorname-contains name

How can we change the ddl selected value to the correct name or id on the other dll? (follow the leader)

i.e.
001 abc
002 efg

ddloperatorid-selected value is 002
then
ddloperatorname- should move to efg (viseversa)

Thanks.

                  Private Function GenerateSourceOper() As DataTable
                      Dim con As New SqlConnection("......")
                      Dim cmd As SqlCommand = con.CreateCommand()
                      cmd.CommandType = CommandType.StoredProcedure
                      cmd.CommandText = "SP_operator_id_and_name"
                      cmd.Parameters.Add(New SqlParameter("@RETURN_VALUE", SqlDbType.Int, 4, ParameterDirection.ReturnValue, False, CType(0, Byte), CType(0, Byte), "", DataRowVersion.Current, Nothing))
                      Dim da As New SqlDataAdapter(cmd)
                      Dim ds As New DataSet()
                      da.Fill(ds,"DataSetName")
                      Return ds.Tables("DataSetName")
                      cmd.dispose
                      cmd.parameters.clear
                      con.close
                  End function

                   Sub Page_Load(Sender As Object, E As EventArgs)
                     If Not Page.IsPostBack Then

                      ddloperatorid.Datasource=GenerateSourceOper().DefaultView
                      ddloperatorid.DataTextField = "supervisor id"
                      ddloperatorid.DataValueField = "supervisor name"

                      ddloperatorname.Datasource=GenerateSourceOper().DefaultView
                      ddloperatorname.DataTextField = "supervisor name"
                      ddloperatorname.DataValueField = "supervisor id"

                      Page.DataBind()
                      ddloperatorid.Items.Insert(0, "Select id")
                      ddloperatorname.Items.Insert(0, "Select name")
                      end if
                  End Sub


0
Comment
Question by:lynnton
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 4

Assisted Solution

by:vladimir_kalashnikov
vladimir_kalashnikov earned 400 total points
ID: 13666388
its actually pretty easy.  first, you have to enable autopostback on both of the dropdowns (in their properties).  Then create the dropdown selecteditemchanged events for both of them (by double clicking them in visual studio).  Then in those methods take the selected text (or value if thats what you are using) and iterate through the other list to find the value that corresponds to that one, then select it.

You could probably find a way to do it without using postbacks, but using javascript instead.  It shouldn't be too difficult, but my javascript sucks, so i won't try to show you that way.
0
 
LVL 1

Author Comment

by:lynnton
ID: 13669324
vladimir_kalashnikov,

auto post back is now set, can you kindly guide me in vb code ?

Thanks.
0
 
LVL 8

Accepted Solution

by:
sriggumma earned 1600 total points
ID: 13669557
lynnton,

1. In aspx page, Set AutoPostBack="True" for first dropdownlist i.e., ddloperatorid
2. In code behind, write code like below:
----->
 Private Sub ddloperatorid_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ddloperatorid.SelectedIndexChanged
        ddloperatorname.SelectedIndex = ddloperatorid.SelectedIndex
    End Sub

Hope this gives you an idea.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:lynnton
ID: 13669622
sriggumma,

Thanks so much.
0
 
LVL 8

Expert Comment

by:sriggumma
ID: 13669776
lynnton,

If you do not want the page getting posted for each selection, you may use javascript like below:

1. Set AutoPostBack="False"  for the dropdownlists.
2. Define a Javascript block in aspx page like below:
----->
<script language="javascript">
   function SetNameDdlById()
   {
      document.getElementById("ddloperatorname").selectedIndex=document.getElementById("ddloperatorid").selectedIndex;
   }
</script>

3. In the code behind of the page, add this line to use the Javascript function.
----->
    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        '..... YOUR REGULAR CODE .......
        ddloperatorid.Attributes.Add("onchange", "JavaScript:SetNameDdlById()")
    End Sub


Hope this helps you.
0
 
LVL 1

Author Comment

by:lynnton
ID: 13669793
sriggumma,

Will it affect my project? once i place the javascript?

where do I place the javascript code? top page?

Thanks.


<%@ Page Language="VB" Debug="true" %>
<%@ Register TagPrefix="wmx" Namespace="Microsoft.Matrix.Framework.Web.UI" Assembly="Microsoft.Matrix.Framework, Version=0.6.0.0, Culture=neutral, PublicKeyToken=6f763c9966660626" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.SqlClient" %>

0
 
LVL 1

Author Comment

by:lynnton
ID: 13670119
sriggumma,

When I change the order of the operatorid DDL to ASC

it was matching the index value for index value

ddloperatorname.SelectedIndex = ddloperatorid.SelectedIndex

how can we change it to select the proper name for that id ?


                      ddloperatorid.Datasource=GenerateSourceOperid().DefaultView <---------arrange by name
                      ddloperatorid.DataTextField = "supervisor id"
                      ddloperatorid.DataValueField = "supervisor name"
                      ddloperatorname.Datasource=GenerateSourceOpername().DefaultView <------arrange by id
                      ddloperatorname.DataTextField = "supervisor name"
                      ddloperatorname.DataValueField = "supervisor id"
   
                      Page.DataBind()

Thanks.
0
 
LVL 8

Expert Comment

by:sriggumma
ID: 13670907
lynnton
>>> where do I place the javascript code? top page?
You can place the javascript anywhere in the aspx page. Ideally, place the code within the <head> and </head> tags.

>>> When I change the order of the operatorid DDL to ASC
Then replace
-----> ddloperatorname.SelectedIndex = ddloperatorid.SelectedIndex

with
-----> ddloperatorname.SelectedIndex = ddloperatorname.Items.IndexOf(ddloperatorname.Items.FindByText(ddloperatorid.SelectedValue))


Hope this gives the idea.
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

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

801 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