Hi kapil Dhawan,
The code you given doesn't work either. Listbox2 item1 just didn't get selected when i click on item1 in listbox1. Did you tried using the code you gave me and did it succeed?
>Hi,
here is the code of a example
i hope it will help it out
if not mail me.....
runat="server">
Item1
Item2
Item3
Item4
runat="server">
A
B
C
D
private void ListBox1_SelectedIndexChanged(object sender, System.EventArgs e)
{
ListBox2.SelectedValue=ListBox1.SelectedItem.Value;
}
>
>
>Hi,
How can I select a record at the same row from listbox1 and listbox2 at the same time?
Hi,
can you please specify the problem in details?
Whatever i have understood from your query is , When you select a record(item) from one listbox , the same item number's record should get selected from another listbox.
if this is your requirement , then on selected Index changed event of listbox1 , you can write
ListBox2.item(itemIndex).selected=true
Hi. This is my codes. The items inside my listboxs are data received from the server.
This is an example of what I want.
I have two listbox. I want to do something like when item in listbox1 is selected the corresponding item in listbox2 will also be selected at the same time. But I not sure how to do it. Can anyone help me?
Example:
Listbox1 item contains: 1,2
Listbox2 item contains: hello, bye
I want something like that. when 1 is selected hello will also be selected and when 2 is selected bye is also selected.
Listbox1: | ListBox2:
1 | hello
2 | bye
My Codes:
#Region "Import Libraries"
Imports System
Imports System.IO
Imports System.Net
Imports System.Net.Sockets
Imports System.Threading
Imports System.Text
Imports System.Xml
#End Region
Partial Public Class PatientMain
Inherits System.Web.UI.Page
Dim mrnArray As New ArrayList
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim reply As New String(Networker.sendAndReceive("
" & vbCrLf))
Dim xmlRead As New XmlTextReader(New StringReader(reply))
Dim mrn As String
Try
While xmlRead.Read()
If xmlRead.Name = "patient" Then
mrn = xmlRead.GetAttribute("mrn")
mrnArray.Add(mrn)
PMListBx1.Items.Add(mrn)
PMListBx2.Items.Add(xmlRead.GetAttribute("firstname") & " " & xmlRead.GetAttribute("lastname"))
End If
End While
Catch ex As Exception
Networker.sendAndReceive("
" & vbCrLf)
Networker.socket.Close()
End Try
End Sub
Protected Sub PMainBtnProceed_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PMBtnProceed.Click
Networker.mrn = mrnArray.Item(PMListBx1.SelectedIndex)
Response.Redirect("~/PatientHistory.aspx")
End Sub
Protected Sub btnOkName_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOkName.Click
Response.Redirect("~/EditPatientMain.aspx")
End Sub
Protected Sub btnOkMRN_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOkMRN.Click
Response.Redirect("~/EditPatientMain.aspx")
End Sub
Private Sub PMListBx1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles PMListBx1.SelectedIndexChanged
'PMListBx2.SelectedIndex = PMListBx1.SelectedIndex
PMListBx2.Items("1").Selected = True
End Sub
Private Sub PMListBx2_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles PMListBx2.SelectedIndexChanged
'PMListBx1.SelectedIndex = PMListBx2.SelectedIndex
PMListBx1.Items("1").Selected = True
End Sub
End Class