|
 |
aspx thread: How do you preselect a value on dropdown or Listbox using ASP.NET code ?
Message #1 by "rk" <ravi@v...> on Fri, 5 Jan 2001 15:02:20 -0000
|
|
can some body help me in preselecting an item from the database to a value
in the list box which is databinded using values from the same database.
Example:
Let us say i am searching for a customer information based on customerid.
I get the customer state based on customerid as 'VA' i would like to
preselect this in a dropdown list of states once the page is loaded. can
some body supply some code.
thx in advance
---
http://www.asptoday.com - the leading site for timely,
in-depth information for ASP developers everywhere.
---
You are currently subscribed to aspx as: $subst('Recip.EmailAddr')
To unsubscribe send a blank email to leave-aspx-$subst('Recip.MemberIDChar')@p2p.wrox.com
Message #2 by "Robert Lair" <mailinglists@a...> on Fri, 5 Jan 2001 10:46:34 -0500
|
|
If you can get the index of the item you want to select then you can set the
item with:
MyDropDownList.SelectedIndex = index
If you only have the value, it is a bit more difficult to select. I have an
example at http://www.eraserver.net/robertlair/example_dropdownbyval.aspx
Not sure if this is what you wanted, let me know
Bob Lair
----- Original Message -----
From: "rk" <ravi@v...>
To: "ASP+" <aspx@p...>
Sent: Friday, January 05, 2001 10:02 AM
Subject: [aspx] How do you preselect a value on dropdown or Listbox using
ASP.NET code ?
> can some body help me in preselecting an item from the database to a value
> in the list box which is databinded using values from the same database.
>
> Example:
>
> Let us say i am searching for a customer information based on customerid.
> I get the customer state based on customerid as 'VA' i would like to
> preselect this in a dropdown list of states once the page is loaded. can
> some body supply some code.
>
> thx in advance
>
---
http://www.asptoday.com - the leading site for timely,
in-depth information for ASP developers everywhere.
---
You are currently subscribed to aspx as: $subst('Recip.EmailAddr')
To unsubscribe send a blank email to leave-aspx-$subst('Recip.MemberIDChar')@p2p.wrox.com
Message #3 by Levent Camlibel <lcamlib@C...> on Fri, 5 Jan 2001 11:25:40 -0500
|
|
Hello rk,
you might Want to use it as I do. The Following code returns index
number in the given DropDownlist and Index Value.
You can use this function as
dropState.SelectedIndex=br.FindIndexForDropDown(dropState, strState);
dropState is a dropDownList
strState is "VA" for example
****************************************************
public Int32 FindIndexForDropDown(DropDownList dr, string IndexValue)
{
for(int i=0;i<dr.Items.Count.ToInt32();i++)
{
if(dr.Items[i].Value.ToString().Equals(IndexValue))
{
return i;
}
}
return 0;
}
levent Camlibel
Friday, January 05, 2001, 10:02:20 AM, you wrote:
r> can some body help me in preselecting an item from the database to a value
r> in the list box which is databinded using values from the same database.
r> Example:
r> Let us say i am searching for a customer information based on customerid.
r> I get the customer state based on customerid as 'VA' i would like to
r> preselect this in a dropdown list of states once the page is loaded. can
r> some body supply some code.
r> thx in advance
--
Best regards,
Levent mailto:lcamlib@c...
---
http://www.asptoday.com - the leading site for timely,
in-depth information for ASP developers everywhere.
---
You are currently subscribed to aspx as: $subst('Recip.EmailAddr')
To unsubscribe send a blank email to leave-aspx-$subst('Recip.MemberIDChar')@p2p.wrox.com
Message #4 by "SATHISH C.G." <cgs@s...> on Mon, 8 Jan 2001 11:09:48 +0530
|
|
HI,
Use the selectedindex property of the combo or the list box to
preselect a value from the combo or list box.
Hope it will help u.
Regards
SATHISH C.G.
----- Original Message -----
From: rk <ravi@v...>
To: ASP+ <aspx@p...>
Sent: Friday, January 05, 2001 8:32 PM
Subject: [aspx] How do you preselect a value on dropdown or Listbox using
ASP.NET code ?
> can some body help me in preselecting an item from the database to a value
> in the list box which is databinded using values from the same database.
>
> Example:
>
> Let us say i am searching for a customer information based on customerid.
> I get the customer state based on customerid as 'VA' i would like to
> preselect this in a dropdown list of states once the page is loaded. can
> some body supply some code.
>
> thx in advance
>
---
http://www.asptoday.com - the leading site for timely,
in-depth information for ASP developers everywhere.
---
You are currently subscribed to aspx as: $subst('Recip.EmailAddr')
To unsubscribe send a blank email to leave-aspx-$subst('Recip.MemberIDChar')@p2p.wrox.com
Message #5 by "David Reidy" <dreidy@c...> on Wed, 10 Jan 2001 08:21:44 +1100
|
|
I use the following code to load data into a drop down, and then select an
entry in a drop down list based on a previously stored registry value. The
first is the winform version of the code, the second is the webform version.
Hope this helps.
David.
Protected Sub cmbLocation_SelectedIndexChanged(ByVal sender As Object,
ByVal e As System.EventArgs)
Dim recRegister As DataRow
Dim intIndex As Integer
intIndex = 0
lngLocationID
CLng(dsLocations.Tables("Locations").Rows(cmbLocation.SelectedIndex).Item("L
ocationID"))
dsRegisters = objIdentity.RegisterList(lngLocationID)
cmbRegister.Text = "-- Select Register --"
For Each recRegister In dsRegisters.Tables("Registers").Rows
cmbRegister.Items.Add(recRegister.Item("Name").ToString)
If recRegister.Item("RegisterID").ToString
GetSetting("Application", "Identity", "RegisterID", "0") Then
cmbRegister.SelectedIndex = intIndex
End If
intIndex += 1
Next
Enable()
End Sub
Public Sub ddlLocation_SelectedIndexChanged(ByVal sender As Object,
ByVal e As System.EventArgs)
Dim objIdentity As IdentityB
Dim DS As DataSet
Dim recRegister As DataRow
Dim strRegister As String
Dim lngCount As Integer
Dim lngSelect As Integer
Try
strRegister = Request.Cookies("Identity")("Register")
Catch
strRegister = ""
End Try
objIdentity = New IdentityB()
DS
objIdentity.RegisterList(ddlLocation.SelectedItem.Value.ToInt64)
ddlRegister.Items.Add("-- Select register --")
lngCount = 0
lngSelect = 0
For Each recRegister In DS.Tables("Registers").Rows
lngCount += 1
ddlRegister.Items.Add(New
ListItem(recRegister.Item("Name").ToString,
recRegister.Item("RegisterID").ToString))
If recRegister.Item("RegisterID").ToString = strRegister Then
lngSelect = lngCount
End If
Next
If lngSelect <> 0 Then
ddlRegister.SelectedIndex = lngSelect
End If
End Sub
---
http://www.asptoday.com - the leading site for timely,
in-depth information for ASP developers everywhere.
---
You are currently subscribed to aspx as: $subst('Recip.EmailAddr')
To unsubscribe send a blank email to leave-aspx-$subst('Recip.MemberIDChar')@p2p.wrox.com
|
|
 |