Saturday, March 24, 2012
populate dropdownlist
_cmd.CommandText = "SELECT workgroupID, workGroupname FROM dbo.workgroup"
_dr = _cmd.ExecuteReader
While _dr.Read
workgroupSelect.Items.Add(_dr("workgroupname"))
workgroupSelect.DataValueField = _dr("workgroupid")
End While
How do I get my id field into the list so that I know which one was selected??
How do I know which one was selected?
Grateful for any help.
Cheersok, I now have
With workgroupSelect
.DataSource = _dr
.DataTextField = "workgroupname"
.DataValueField = "workgroupid"
.DataBind()
.Items.Insert(0, "<- Select a Work Group ->")
End With
so all I need now is to know is the workgroupId of the one selected??
Cheers
try :
workgroupSelect.SelectedItem.Value
I have tried that,
I have ..
Protected Sub workgroupSelect_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles workgroupSelect.SelectedIndexChanged
Dim strselected As String
strselected = workgroupSelect.SelectedValue.ToString
Label1.Text = strselected
End Sub
but the only I can get the label text to show the value is to set the dropdowncontrol to postback = true
is there a way around this??
is the value actually changing even if I cant see it in the label??
Thanks
The value would change but there is no way to see it refreshed unless the postback is activated. Such is web development :sick:
Populate textbox from item selected in a drop down list
I have a page that has a dropdown list of customers. I want to select a customer from that dropdown and populate the appropriate textboxes.
So when I select 'John Smith' from the dropdown list I have a form with textboxes for first name, last name, accout id, etc that needs to populate accordingly. I am using VB.net with MS SQL. I have been successful populating the dropdown list from the DB. Where I am lost is populating the appropriate textboxes for the customer selected in the dropdown list. Any help is appreciated.Hi,
If you are having the dropdownlist and the textbox in the same form, then you need to do as below:-
Set the autopostback property for the dropdownlist to true. This will make the dropdownlist post back to the server, once an element is selected. Then, you can put the following code in your codebehind file to get the selected item.
If Not IsPostBack Then
textbox1.text = dropdownlist1.SelectedItem.Text
End If
If you are having the textbox in a different form, then you need to pass the selected value by querystring to that form.
If Not IsPostBack Then
Response.Redirect("NewForm.aspx?name=" & dropdownlist1.SelectedItem.Text)
End If
Then in the new form, you can get the value using the following code:-
textbox1.text = Request.Params("name")
Hope it helps.
Something to keep in mind:
The name of the user (or whatever) may not be unique. You can have two people with the name "John Smith." You propably have a column in your DB that is unique for each person like UserID or whatever.
So when you update the dropdownlist from the database, you need to retrieve the unique id for each person as well, so that when the index of the selected index in the drop down list changes, you can use the corresponding unique ID to retrieve the other info from the database.
I cant remember exactly, but you should take a loot at the dropdown control itself. Many such controls have a 'Value' for each item in them. You van set the 'Value' to the unique ID somehow.
Youll have to take a look...
Wednesday, March 21, 2012
populate txtbox
txtbox2 = DateAdd(DateInterval.Day, 1, CDate(txtbox1.Text))
Is this the proper way to do this? Does anyone have an example?
thanks,
eyeI've used javascript but I normally find some code examples that I can adapt so I can't remember the exacxt way to do what you want. If you look at some javascript sites you should find it easily enough.
populating a Drop down list
I need to populate a drop down list when the user clicks
on the arrow button.
how do i do this.
Should i use a html select control or is it possible
using the asp:dropdownlistBoth are ok.
for saving program code, you can choose DropDownList,
if your data come from db, two lines will give your the result
ddl.DataSource = yourProcedure;
ddl.DataBind();
> hello,
> I need to populate a drop down list when the user clicks
> on the arrow button.
> how do i do this.
> Should i use a html select control or is it possible
> using the asp:dropdownlist
What i mean is that the list should only be populated
when the user clicks on it.
Until then it should be empty
>--Original Message--
>Both are ok.
>for saving program code, you can choose DropDownList,
> if your data come from db, two lines will give your the
result
> ddl.DataSource = yourProcedure;
> ddl.DataBind();
>> hello,
>>
>> I need to populate a drop down list when the user
clicks
>> on the arrow button.
>>
>> how do i do this.
>>
>> Should i use a html select control or is it possible
>> using the asp:dropdownlist
>>
>>
>
>.
Can you supply your reasoning for this requirement? This is not the
normal usage of this type of control. You can certainly populate the
list based on selections from other controls, but it might be
difficult to do using the onclick event of the listbox itself.
On Mon, 5 Jul 2004 07:28:15 -0700, "Casey"
<anonymous@.discussions.microsoft.com> wrote:
>
>What i mean is that the list should only be populated
>when the user clicks on it.
>Until then it should be empty
>
>
>>--Original Message--
>>Both are ok.
>>
>>for saving program code, you can choose DropDownList,
>>
>> if your data come from db, two lines will give your the
>result
>> ddl.DataSource = yourProcedure;
>> ddl.DataBind();
>>
>>> hello,
>>>
>>> I need to populate a drop down list when the user
>clicks
>>> on the arrow button.
>>>
>>> how do i do this.
>>>
>>> Should i use a html select control or is it possible
>>> using the asp:dropdownlist
>>>
>>>
>>
>>
>>.
>
Dan,
I am connecting to server at a distant location to
retrieve the data for the listbox, and the data has to be
loaded up only when the user wants to look at the
information,
I know there are other ways of doing this but this is
requested by the user
can you give me any ideas on this..
>--Original Message--
>Can you supply your reasoning for this requirement? This
is not the
>normal usage of this type of control. You can certainly
populate the
>list based on selections from other controls, but it
might be
>difficult to do using the onclick event of the listbox
itself.
>
>On Mon, 5 Jul 2004 07:28:15 -0700, "Casey"
><anonymous@.discussions.microsoft.com> wrote:
>>
>>
>>What i mean is that the list should only be populated
>>when the user clicks on it.
>>
>>Until then it should be empty
>>
>>
>>
>>
>>>--Original Message--
>>>Both are ok.
>>>
>>>for saving program code, you can choose DropDownList,
>>>
>>> if your data come from db, two lines will give your
the
>>result
>>> ddl.DataSource = yourProcedure;
>>> ddl.DataBind();
>>>
>>>> hello,
>>>>
>>>> I need to populate a drop down list when the user
>>clicks
>>>> on the arrow button.
>>>>
>>>> how do i do this.
>>>>
>>>> Should i use a html select control or is it possible
>>>> using the asp:dropdownlist
>>>>
>>>>
>>>
>>>
>>>.
>>>
>.
There is a user event that occurs when you click on the dropdown list
I think (not 100% sure). You may be able to link to that. However...
If you are going to go to the server to get the data, this will be a
significant pause to build the list. Also, when you come back, you
would have to manually "open" that list as if you just clicked on it.
Not exactly a smooth transition.
I suggest that you should be able to determine when the list would
need to be built and do this when necessary. Worst case, provide a
button that says "Load List" that the user can click and then populate
the dropdown list.
On Mon, 5 Jul 2004 14:19:26 -0700, "Casey"
<anonymous@.discussions.microsoft.com> wrote:
>Dan,
> I am connecting to server at a distant location to
>retrieve the data for the listbox, and the data has to be
>loaded up only when the user wants to look at the
>information,
>I know there are other ways of doing this but this is
>requested by the user
>can you give me any ideas on this..
>
>>--Original Message--
>>Can you supply your reasoning for this requirement? This
>is not the
>>normal usage of this type of control. You can certainly
>populate the
>>list based on selections from other controls, but it
>might be
>>difficult to do using the onclick event of the listbox
>itself.
>>
>>
>>On Mon, 5 Jul 2004 07:28:15 -0700, "Casey"
>><anonymous@.discussions.microsoft.com> wrote:
>>
>>>
>>>
>>>What i mean is that the list should only be populated
>>>when the user clicks on it.
>>>
>>>Until then it should be empty
>>>
>>>
>>>
>>>
>>>>--Original Message--
>>>>Both are ok.
>>>>
>>>>for saving program code, you can choose DropDownList,
>>>>
>>>> if your data come from db, two lines will give your
>the
>>>result
>>>> ddl.DataSource = yourProcedure;
>>>> ddl.DataBind();
>>>>
>>>>> hello,
>>>>>
>>>>> I need to populate a drop down list when the user
>>>clicks
>>>>> on the arrow button.
>>>>>
>>>>> how do i do this.
>>>>>
>>>>> Should i use a html select control or is it possible
>>>>> using the asp:dropdownlist
>>>>>
>>>>>
>>>>
>>>>
>>>>.
>>>>
>>
>>.
>
thanks for your help dan..
I will take your advice,
regards
casey
>--Original Message--
>There is a user event that occurs when you click on the
dropdown list
>I think (not 100% sure). You may be able to link to
that. However...
>If you are going to go to the server to get the data,
this will be a
>significant pause to build the list. Also, when you come
back, you
>would have to manually "open" that list as if you just
clicked on it.
>Not exactly a smooth transition.
>I suggest that you should be able to determine when the
list would
>need to be built and do this when necessary. Worst case,
provide a
>button that says "Load List" that the user can click and
then populate
>the dropdown list.
>
>On Mon, 5 Jul 2004 14:19:26 -0700, "Casey"
><anonymous@.discussions.microsoft.com> wrote:
>>Dan,
>>
>> I am connecting to server at a distant location to
>>retrieve the data for the listbox, and the data has to
be
>>loaded up only when the user wants to look at the
>>information,
>>
>>I know there are other ways of doing this but this is
>>requested by the user
>>
>>can you give me any ideas on this..
>>
>>
>>
>>>--Original Message--
>>>Can you supply your reasoning for this requirement?
This
>>is not the
>>>normal usage of this type of control. You can
certainly
>>populate the
>>>list based on selections from other controls, but it
>>might be
>>>difficult to do using the onclick event of the listbox
>>itself.
>>>
>>>
>>>On Mon, 5 Jul 2004 07:28:15 -0700, "Casey"
>>><anonymous@.discussions.microsoft.com> wrote:
>>>
>>>>
>>>>
>>>>What i mean is that the list should only be populated
>>>>when the user clicks on it.
>>>>
>>>>Until then it should be empty
>>>>
>>>>
>>>>
>>>>
>>>>>--Original Message--
>>>>>Both are ok.
>>>>>
>>>>>for saving program code, you can choose DropDownList,
>>>>>
>>>>> if your data come from db, two lines will give your
>>the
>>>>result
>>>>> ddl.DataSource = yourProcedure;
>>>>> ddl.DataBind();
>>>>>
>>>>>> hello,
>>>>>>
>>>>>> I need to populate a drop down list when the user
>>>>clicks
>>>>>> on the arrow button.
>>>>>>
>>>>>> how do i do this.
>>>>>>
>>>>>> Should i use a html select control or is it
possible
>>>>>> using the asp:dropdownlist
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>>.
>>>>>
>>>
>>>.
>>>
>.
populating a Drop down list
I need to populate a drop down list when the user clicks
on the arrow button.
how do i do this.
Should i use a html select control or is it possible
using the asp:dropdownlistBoth are ok.
for saving program code, you can choose DropDownList,
if your data come from db, two lines will give your the result
ddl.DataSource = yourProcedure;
ddl.DataBind();
> hello,
> I need to populate a drop down list when the user clicks
> on the arrow button.
> how do i do this.
> Should i use a html select control or is it possible
> using the asp:dropdownlist
>
What i mean is that the list should only be populated
when the user clicks on it.
Until then it should be empty
>--Original Message--
>Both are ok.
>for saving program code, you can choose DropDownList,
> if your data come from db, two lines will give your the
result
> ddl.DataSource = yourProcedure;
> ddl.DataBind();
>
clicks
>
>.
>
Can you supply your reasoning for this requirement? This is not the
normal usage of this type of control. You can certainly populate the
list based on selections from other controls, but it might be
difficult to do using the onclick event of the listbox itself.
On Mon, 5 Jul 2004 07:28:15 -0700, "Casey"
<anonymous@.discussions.microsoft.com> wrote:
>
>What i mean is that the list should only be populated
>when the user clicks on it.
>Until then it should be empty
>
>
>result
>clicks
Dan,
I am connecting to server at a distant location to
retrieve the data for the listbox, and the data has to be
loaded up only when the user wants to look at the
information,
I know there are other ways of doing this but this is
requested by the user
can you give me any ideas on this..
>--Original Message--
>Can you supply your reasoning for this requirement? This
is not the
>normal usage of this type of control. You can certainly
populate the
>list based on selections from other controls, but it
might be
>difficult to do using the onclick event of the listbox
itself.
>
>On Mon, 5 Jul 2004 07:28:15 -0700, "Casey"
><anonymous@.discussions.microsoft.com> wrote:
>
the
>.
>
There is a user event that occurs when you click on the dropdown list
I think (not 100% sure). You may be able to link to that. However...
If you are going to go to the server to get the data, this will be a
significant pause to build the list. Also, when you come back, you
would have to manually "open" that list as if you just clicked on it.
Not exactly a smooth transition.
I suggest that you should be able to determine when the list would
need to be built and do this when necessary. Worst case, provide a
button that says "Load List" that the user can click and then populate
the dropdown list.
On Mon, 5 Jul 2004 14:19:26 -0700, "Casey"
<anonymous@.discussions.microsoft.com> wrote:
>Dan,
> I am connecting to server at a distant location to
>retrieve the data for the listbox, and the data has to be
>loaded up only when the user wants to look at the
>information,
>I know there are other ways of doing this but this is
>requested by the user
>can you give me any ideas on this..
>
>
>is not the
>populate the
>might be
>itself.
>the
thanks for your help dan..
I will take your advice,
regards
casey
>--Original Message--
>There is a user event that occurs when you click on the
dropdown list
>I think (not 100% sure). You may be able to link to
that. However...
>If you are going to go to the server to get the data,
this will be a
>significant pause to build the list. Also, when you come
back, you
>would have to manually "open" that list as if you just
clicked on it.
>Not exactly a smooth transition.
>I suggest that you should be able to determine when the
list would
>need to be built and do this when necessary. Worst case,
provide a
>button that says "Load List" that the user can click and
then populate
>the dropdown list.
>
>On Mon, 5 Jul 2004 14:19:26 -0700, "Casey"
><anonymous@.discussions.microsoft.com> wrote:
>
be
This
certainly
possible
>.
>
Friday, March 16, 2012
populating a list box by alphabetical surname
I have a listbox contianing strings which ahs been populated from a databsae via "SELECT * FROM researchers"
i.e
John Doe www.johndoe.com
David Allen www.daveallen.com
Andrew Rodgers www.andrewdavidson.com
..
I need this to be displayed as
David Allen www.daveallen.com
John Doe www.johndoe.com
Andrew Rodgers www.andrewdavidson.com
i.e alphabetically by surname?
How do I do this?SELECT * FROM researchers ORDER BY LastName ASC
Populating Drop down box value
i want to populate the drop down box values based on the first drop down box
value, actually i have form in which user will select a car maker and based
on that value below 2 drop down box values will be populated
For example user select Suzuki and based on that value in one drop down car
models will be shown and in secound one car type will be shown, how can i do
it in ASP.NET, please tell me, i'm using MS-Access DB.
Thanks.in the onselectedindexchanged event of the first control you need to
bind the second dropdown to a datasource passing the selected item
value from the first dropdown (control.selecteditem.value)
for instance:
if model id is an integer:
string selectCommand = "select model_id, model from table where
model_id =" + ddlMake.selecteditem.value;
if model id is an string:
string selectCommand = "select model_id, model from table where
model_id ='" + ddlMake.selecteditem.value + "'";
Populating Drop down box value
i want to populate the drop down box values based on the first drop down box
value, actually i have form in which user will select a car maker and based
on that value below 2 drop down box values will be populated
For example user select Suzuki and based on that value in one drop down car
models will be shown and in secound one car type will be shown, how can i do
it in ASP.NET, please tell me, i'm using MS-Access DB.
Thanks.in the onselectedindexchanged event of the first control you need to
bind the second dropdown to a datasource passing the selected item
value from the first dropdown (control.selecteditem.value)
for instance:
if model id is an integer:
string selectCommand = "select model_id, model from table where
model_id =" + ddlMake.selecteditem.value;
if model id is an string:
string selectCommand = "select model_id, model from table where
model_id ='" + ddlMake.selecteditem.value + "'";
Populating Dropdown List
I am not able to select any value from my dropdownlist,it always returns the first value. Based on the selection the corresponding record should be displayed in a text box. I have given my code here. I am totally frustrated. Pls check it out.
Page_load event
If Not Page.IsPostBack Then
sql = "select scode from supplier"
cmd = New SqlCommand(sql, con)
read = cmd.ExecuteReader
While (read.Read)
ddlscode.Items.Add(read.Item(0))
End While
ddlscode.DataBind()
End If
Private Sub ddlscode_SelectedIndexChanged(...)...
Dim sql As String
Dim i As Integer
Dim tempscode As String
con.Open()
sql = "select * from supplier "
cmd = New SqlCommand(sql, con)
adap = New SqlDataAdapter(cmd)
dt = New DataTable()
adap.Fill(dt)
For i = 0 To dt.Rows.Count - 1
If dt.Rows(i).Item("scode") = ddlscode.SelectedItem.Value Then
txtsaddr.Text = dt.Rows(i).Item("saddr")
End If
Next
read.Read()
read.Close()
con.Close()
End Subtry setting the View state of the control to true.
Set AutoPostback property equal to true.and write this code in page load
if(!page.IsPostback)
{
SqlDataReader rr;
rr=Com.ExecuteReader();
DropDownList1.DataSource=rr;
DropDownList1.DataBind();
}
Select the Value Selected value of DropdownList as
DropDownList1.SelectedItem.Text
I hope this will work but this is in c# convert into Vb
Not sure what's causing you problem, but it might be linked to your loop in the second function. A better way of handling it might be:
Private Sub ddlscode_SelectedIndexChanged(...)...
Dim sql As String
con.Open()
sql = "select saddr from supplier where scode = '" & ddlscode.SelectedItem.Value & "'"
Dim sqlComm As new System.Data.SqlClient.SqlCommand(sql,con);
txtsaddr.Text = sqlComm.ExecuteScalar()
con.Close()
End Sub
The SQL should only return 1 row (I've assumed the selected code is a text value) and the ExecuteScalar call returns the first column (in this case the 'saddr')
Hope this helps,
Nic