lynnton
asked on
two DDL -follow the leader
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.StoredProcedur e
cmd.CommandText = "SP_operator_id_and_name"
cmd.Parameters.Add(New SqlParameter("@RETURN_VALU E", SqlDbType.Int, 4, ParameterDirection.ReturnV alue, 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=G enerateSou rceOper(). DefaultVie w
ddloperatorid.DataTextFiel d = "supervisor id"
ddloperatorid.DataValueFie ld = "supervisor name"
ddloperatorname.Datasource =GenerateS ourceOper( ).DefaultV iew
ddloperatorname.DataTextFi eld = "supervisor name"
ddloperatorname.DataValueF ield = "supervisor id"
Page.DataBind()
ddloperatorid.Items.Insert (0, "Select id")
ddloperatorname.Items.Inse rt(0, "Select name")
end if
End Sub
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.StoredProcedur
cmd.CommandText = "SP_operator_id_and_name"
cmd.Parameters.Add(New SqlParameter("@RETURN_VALU
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=G
ddloperatorid.DataTextFiel
ddloperatorid.DataValueFie
ddloperatorname.Datasource
ddloperatorname.DataTextFi
ddloperatorname.DataValueF
Page.DataBind()
ddloperatorid.Items.Insert
ddloperatorname.Items.Inse
end if
End Sub
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
sriggumma,
Thanks so much.
Thanks so much.
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("d dloperator name").sel ectedIndex =document. getElement ById("ddlo peratorid" ).selected Index;
}
</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.A dd("onchan ge", "JavaScript:SetNameDdlById ()")
End Sub
Hope this helps you.
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("d
}
</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.A
End Sub
Hope this helps you.
ASKER
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.Matri x.Framewor k.Web.UI" Assembly="Microsoft.Matrix .Framework , Version=0.6.0.0, Culture=neutral, PublicKeyToken=6f763c99666 60626" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.Sql Client" %>
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.Matri
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.Sql
ASKER
sriggumma,
When I change the order of the operatorid DDL to ASC
it was matching the index value for index value
ddloperatorname.SelectedIn dex = ddloperatorid.SelectedInde x
how can we change it to select the proper name for that id ?
ddloperatorid.Datasource=G enerateSou rceOperid( ).DefaultV iew <---------arrange by name
ddloperatorid.DataTextFiel d = "supervisor id"
ddloperatorid.DataValueFie ld = "supervisor name"
ddloperatorname.Datasource =GenerateS ourceOpern ame().Defa ultView <------arrange by id
ddloperatorname.DataTextFi eld = "supervisor name"
ddloperatorname.DataValueF ield = "supervisor id"
Page.DataBind()
Thanks.
When I change the order of the operatorid DDL to ASC
it was matching the index value for index value
ddloperatorname.SelectedIn
how can we change it to select the proper name for that id ?
ddloperatorid.Datasource=G
ddloperatorid.DataTextFiel
ddloperatorid.DataValueFie
ddloperatorname.Datasource
ddloperatorname.DataTextFi
ddloperatorname.DataValueF
Page.DataBind()
Thanks.
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.SelectedIn dex = ddloperatorid.SelectedInde x
with
-----> ddloperatorname.SelectedIn dex = ddloperatorname.Items.Inde xOf(ddlope ratorname. Items.Find ByText(ddl operatorid .SelectedV alue))
Hope this gives the idea.
>>> 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.SelectedIn
with
-----> ddloperatorname.SelectedIn
Hope this gives the idea.
ASKER
auto post back is now set, can you kindly guide me in vb code ?
Thanks.