Showing posts with label drop. Show all posts
Showing posts with label drop. Show all posts

Monday, March 26, 2012

Populate a Drop Down List

Hello,

i have an ASP.NET / VB page where i have a few 4 groups of Drop Down Lists.
Each group of Drop Down Lists include 3 Drop Down Lists for date such as:
DAY, MONTH, and YEAR.

I don't want to insert the values and text to each drop down list.

So i want to create a script that populates a certain Drop Down List with
certain values when page loads such as:

Day: 1,2,3,4,5,...
Month: January, February, ..., December
Year: 2004, 2003, 2002, 2001, ...

This way in that script i will be able to control how all the Drop Down
Lists are populated just bu changing the script.

Can you help me out?

Thank You,
Miguel

P.S: I am working with ASP.NET / VB.First thing is to remove the word "script" from your vocabulary. VB .NET is
not VBScript.

You could write some code in the .aspx.vb (code-behind) Page_Load event that
will populate the drop down lists by determining today's date (now) and then
use the various methods of the now value to extract the day, month and year.
Then, via looping, you can build up the items on the lists.

"Miguel Dias Moura" <web001@.27NOSPAMlamps.com> wrote in message
news:OyUB0xBUEHA.1012@.TK2MSFTNGP09.phx.gbl...
> Hello,
> i have an ASP.NET / VB page where i have a few 4 groups of Drop Down
Lists.
> Each group of Drop Down Lists include 3 Drop Down Lists for date such as:
> DAY, MONTH, and YEAR.
> I don't want to insert the values and text to each drop down list.
> So i want to create a script that populates a certain Drop Down List with
> certain values when page loads such as:
> Day: 1,2,3,4,5,...
> Month: January, February, ..., December
> Year: 2004, 2003, 2002, 2001, ...
> This way in that script i will be able to control how all the Drop Down
> Lists are populated just bu changing the script.
> Can you help me out?
> Thank You,
> Miguel
> P.S: I am working with ASP.NET / VB.
Create a ListItem. Set the value and the text properties and then add it to
the drop down list. I'm not sure about VB.Net but in C# it would be
something like this:

using System.Globalization;

dtfi = new DateTimeFormatInfo();
for (int month = 1; month < 13; month ++)
{
ListItem li = new ListItem();
li.Text = dtfi.GetMonthName(month);
li.Value = month;
ddlMonth.Items.Add(li);
}

Do basically the same thing for each drop down list. Translating the C# to
VB should be pretty straight forward.

Hope this helps,

Dale

"Miguel Dias Moura" <web001@.27NOSPAMlamps.com> wrote in message
news:OyUB0xBUEHA.1012@.TK2MSFTNGP09.phx.gbl...
> Hello,
> i have an ASP.NET / VB page where i have a few 4 groups of Drop Down
Lists.
> Each group of Drop Down Lists include 3 Drop Down Lists for date such as:
> DAY, MONTH, and YEAR.
> I don't want to insert the values and text to each drop down list.
> So i want to create a script that populates a certain Drop Down List with
> certain values when page loads such as:
> Day: 1,2,3,4,5,...
> Month: January, February, ..., December
> Year: 2004, 2003, 2002, 2001, ...
> This way in that script i will be able to control how all the Drop Down
> Lists are populated just bu changing the script.
> Can you help me out?
> Thank You,
> Miguel
> P.S: I am working with ASP.NET / VB.
One obvious error in my code, make 2nd line:

DateTimeFormatInfo dtfi = new DateTimeFormatInfo();

But then, you have to convert the concept into VB.Net anyway, so it probably
didn't throw you too much.

Good luck

Dale

"DalePres" <don-t-spa-m-me@.lea-ve-me-a-lone--.com> wrote in message
news:uyIxbbCUEHA.1012@.TK2MSFTNGP09.phx.gbl...
> Create a ListItem. Set the value and the text properties and then add it
to
> the drop down list. I'm not sure about VB.Net but in C# it would be
> something like this:
> using System.Globalization;
> dtfi = new DateTimeFormatInfo();
> for (int month = 1; month < 13; month ++)
> {
> ListItem li = new ListItem();
> li.Text = dtfi.GetMonthName(month);
> li.Value = month;
> ddlMonth.Items.Add(li);
> }
> Do basically the same thing for each drop down list. Translating the C#
to
> VB should be pretty straight forward.
> Hope this helps,
> Dale
>
> "Miguel Dias Moura" <web001@.27NOSPAMlamps.com> wrote in message
> news:OyUB0xBUEHA.1012@.TK2MSFTNGP09.phx.gbl...
> > Hello,
> > i have an ASP.NET / VB page where i have a few 4 groups of Drop Down
> Lists.
> > Each group of Drop Down Lists include 3 Drop Down Lists for date such
as:
> > DAY, MONTH, and YEAR.
> > I don't want to insert the values and text to each drop down list.
> > So i want to create a script that populates a certain Drop Down List
with
> > certain values when page loads such as:
> > Day: 1,2,3,4,5,...
> > Month: January, February, ..., December
> > Year: 2004, 2003, 2002, 2001, ...
> > This way in that script i will be able to control how all the Drop Down
> > Lists are populated just bu changing the script.
> > Can you help me out?
> > Thank You,
> > Miguel
> > P.S: I am working with ASP.NET / VB.

Populate a Drop Down List

Hello,
i have an ASP.NET / VB page where i have a few 4 groups of Drop Down Lists.
Each group of Drop Down Lists include 3 Drop Down Lists for date such as:
DAY, MONTH, and YEAR.
I don't want to insert the values and text to each drop down list.
So i want to create a script that populates a certain Drop Down List with
certain values when page loads such as:
Day: 1,2,3,4,5,...
Month: January, February, ..., December
Year: 2004, 2003, 2002, 2001, ...
This way in that script i will be able to control how all the Drop Down
Lists are populated just bu changing the script.
Can you help me out?
Thank You,
Miguel
P.S: I am working with ASP.NET / VB.First thing is to remove the word "script" from your vocabulary. VB .NET is
not VBScript.
You could write some code in the .aspx.vb (code-behind) Page_Load event that
will populate the drop down lists by determining today's date (now) and then
use the various methods of the now value to extract the day, month and year.
Then, via looping, you can build up the items on the lists.
"Miguel Dias Moura" <web001@.27NOSPAMlamps.com> wrote in message
news:OyUB0xBUEHA.1012@.TK2MSFTNGP09.phx.gbl...
> Hello,
> i have an ASP.NET / VB page where i have a few 4 groups of Drop Down
Lists.
> Each group of Drop Down Lists include 3 Drop Down Lists for date such as:
> DAY, MONTH, and YEAR.
> I don't want to insert the values and text to each drop down list.
> So i want to create a script that populates a certain Drop Down List with
> certain values when page loads such as:
> Day: 1,2,3,4,5,...
> Month: January, February, ..., December
> Year: 2004, 2003, 2002, 2001, ...
> This way in that script i will be able to control how all the Drop Down
> Lists are populated just bu changing the script.
> Can you help me out?
> Thank You,
> Miguel
> P.S: I am working with ASP.NET / VB.
>
Create a ListItem. Set the value and the text properties and then add it to
the drop down list. I'm not sure about VB.Net but in C# it would be
something like this:
using System.Globalization;
dtfi = new DateTimeFormatInfo();
for (int month = 1; month < 13; month ++)
{
ListItem li = new ListItem();
li.Text = dtfi.GetMonthName(month);
li.Value = month;
ddlMonth.Items.Add(li);
}
Do basically the same thing for each drop down list. Translating the C# to
VB should be pretty straight forward.
Hope this helps,
Dale
"Miguel Dias Moura" <web001@.27NOSPAMlamps.com> wrote in message
news:OyUB0xBUEHA.1012@.TK2MSFTNGP09.phx.gbl...
> Hello,
> i have an ASP.NET / VB page where i have a few 4 groups of Drop Down
Lists.
> Each group of Drop Down Lists include 3 Drop Down Lists for date such as:
> DAY, MONTH, and YEAR.
> I don't want to insert the values and text to each drop down list.
> So i want to create a script that populates a certain Drop Down List with
> certain values when page loads such as:
> Day: 1,2,3,4,5,...
> Month: January, February, ..., December
> Year: 2004, 2003, 2002, 2001, ...
> This way in that script i will be able to control how all the Drop Down
> Lists are populated just bu changing the script.
> Can you help me out?
> Thank You,
> Miguel
> P.S: I am working with ASP.NET / VB.
>
One obvious error in my code, make 2nd line:
DateTimeFormatInfo dtfi = new DateTimeFormatInfo();
But then, you have to convert the concept into VB.Net anyway, so it probably
didn't throw you too much.
Good luck
Dale
"DalePres" <don-t-spa-m-me@.lea-ve-me-a-lone--.com> wrote in message
news:uyIxbbCUEHA.1012@.TK2MSFTNGP09.phx.gbl...
> Create a ListItem. Set the value and the text properties and then add it
to
> the drop down list. I'm not sure about VB.Net but in C# it would be
> something like this:
> using System.Globalization;
> dtfi = new DateTimeFormatInfo();
> for (int month = 1; month < 13; month ++)
> {
> ListItem li = new ListItem();
> li.Text = dtfi.GetMonthName(month);
> li.Value = month;
> ddlMonth.Items.Add(li);
> }
> Do basically the same thing for each drop down list. Translating the C#
to
> VB should be pretty straight forward.
> Hope this helps,
> Dale
>
> "Miguel Dias Moura" <web001@.27NOSPAMlamps.com> wrote in message
> news:OyUB0xBUEHA.1012@.TK2MSFTNGP09.phx.gbl...
> Lists.
as:
with
>

Populate a label with text from a drop down list box

I know this is probably real easy but I can't figure it out.
I'm trying to grab the text that appears in a drop down list server control
and place it in a label server control on the same page. I can get the
selected value, that's easy. But I want the text.
Thanksddl.SelectedItem.Text
Eliyahu
"Mardy" <Mardy@.discussions.microsoft.com> wrote in message
news:983E0BF1-2741-4B22-920F-6F7708CA712B@.microsoft.com...
> I know this is probably real easy but I can't figure it out.
> I'm trying to grab the text that appears in a drop down list server
control
> and place it in a label server control on the same page. I can get the
> selected value, that's easy. But I want the text.
> Thanks
>

Populate a label with text from a drop down list box

I know this is probably real easy but I can't figure it out.

I'm trying to grab the text that appears in a drop down list server control
and place it in a label server control on the same page. I can get the
selected value, that's easy. But I want the text.

Thanksddl.SelectedItem.Text

Eliyahu

"Mardy" <Mardy@.discussions.microsoft.com> wrote in message
news:983E0BF1-2741-4B22-920F-6F7708CA712B@.microsoft.com...
> I know this is probably real easy but I can't figure it out.
> I'm trying to grab the text that appears in a drop down list server
control
> and place it in a label server control on the same page. I can get the
> selected value, that's easy. But I want the text.
> Thanks

Saturday, March 24, 2012

Populate Drop Down from SQL

Welp, here is a simple one. I'm trying to teach myself asp.net and run into problems here and there...

If I'm not doing this the most efficiant way let me know!

I have a SQL table that contains a list of names, this list may change from time to time, and I plan to have another form to update this list when I get a bit more educated and start fine tuning(:->)

Anyhow with that in mind...I want a drop down list to display items from this SQL database, keeping in mind that I want to post value to another sql table...Once again I may be doing this totally the wrong way, but hey I'm learning!

So what I've managed to do is create a connect, and read the data into a datatable. I read it into the datatable, then bound it to a datagrid so I could see that I actually did it... and it worked!! yippie!!
so now I've removed the data table, and am attempting to use the same type connection to itterate(??) through a for each loop to populate the items in my dropdown list from the data table...

ok blah blah blah huh..here is the code I have, and I'm stuck at how to itterate and display the data, keeping in mind that I want this dropdown to post the text in the dropdown. I may have lots of extras I don't need in there also..hey I'm a newbie at this!
Thanks
Josh

------code--------
Private Sub DropDownManagers_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DropDownManagers.SelectedIndexChanged

Dim ConnStr As String
Dim SQL As String
Dim MySqlConn As New SqlConnection(ConnStr)
Dim FinDataSet As New DataSet
Dim FinDataTable As DataTable
Dim FinDataRow As DataRow
Dim FinDataColumn As DataColumn
Dim MySqlAdapter As New SqlDataAdapter(SQL, ConnStr)
Dim MySqlCB As New SqlCommandBuilder(MySqlAdapter)
ConnStr = "server=(local);database=ProjDms; " & _
"Trusted_Connection=yes"
SQL = "SELECT * FROM FinManagers"
FinDataSet.ReadXmlSchema(Server.MapPath("Managers.xsd"))

'Fill the dataset from SQL
MySqlAdapter.Fill(FinDataSet)

For Each FinDataRow In FinDataTable.Rows
'HERE IS MY PROBLEM AS FAR AS I KNOW
Next
End SubYou don't have to iterate. You can databind the dropdownlist to the data directly, provided you tell it which fields are the text and value fields...
I guess I have some more reading to do huh ?? :->


For Each FinDataRow In FinDataTable.Rows
ddlname.Items.Add(new listItem(FinDataRow("FieldName").ToString,FinDataRow("FieldName").ToString) )
Next

or
not iterating


ddlname.DataSource=FinDataTable
ddlname.DataTextField=FinDataTable.Columns("fieldName").ToString
ddlname.DataValueField=FinDataTable.Columns("fieldName").ToString
ddlname.DataBind

Got it working.

I didn't use a direct databind to the sql to populate as I couldn't figure it out...or at least it was easier to figure out how to do it binding to a dataset, as the samples in the book I bought only show binding other types of things to data sets rather than directly to sql, and as I'm a newb, the information about binding the dropdown to the dataset provided in the previous post made the task much easier.

Thanks for the help!!!!!
Problem number 1 solved :-
Josh

Populate drop down list with sql query (contains IF)

I have a drop down list and it is to get it's 'text' and 'value' from a table. The table contains 3 columns:
Title, Name, Id1, Id2
if Id1 is NOT blank then the 'text' value of the drop down list should be:
Name + "(" + Id1 + ")"
else
Name + "(" + Id2 + ")"
I believe the easiest way is to construct the above IF statement is to use SQL query, then pass the parameter to the DataTextField property. However, i seemed to be getting an error. Also any help on the SQL IF statement will be appreciated...
This is what i have so far...(without the IF statement as i'm not sure how to construct the IF statement in SQL)
Sub Page_Load(sender as Object, e as EventArgs)
If Not Page.IsPostBack Then
dropDownList.DataSource = ToGetDataTable()
dropDownList.DataValueField = "MyNewColumn"
dropDownList.DataTextField = "Name"
dropDownList.DataBind()
End if
End Sub

Function ToGetDataTable() As System.Data.IDataReader
Dim connectionString As String = "server='(local)';..................."
Dim dbConnection As System.Data.IDbConnection = New System.Data.SqlClient.SqlConnection(connectionString)

Dim queryString As String = "SELECT Title, Name + ' ( ' + Id1 + ')' AS MyNewColumn FROM MyTableName"
Dim dbCommand As System.Data.IDbCommand = New System.Data.SqlClient.SqlCommand
dbCommand.CommandText = queryString
dbCommand.Connection = dbConnection

dbConnection.Open
Dim dataReader As System.Data.IDataReader = dbCommand.ExecuteReader(System.Data.CommandBehavior.CloseConnection)

Return dataReader
End Function

Do you have sufficient rights on your SQL Server box to create auser-defined function? That seems to be the best way to go aboutthis; you would simply select Title, Name (which is a terrible name fora database field), and MyFunction(Name, Id1, Id2) where MyFunctionwould do the work.
If you don't have this option, you could pull all necessary columns,put them into a DataTable, and then run through it, appending theappropriate values in one particular column.

Populate dropdownlist using table data + text

I have a drop down list and the first option need to be 'ALL', then the remaining options are retrieved from a column of a table. How can this be achieved?
Thanks...I'm not sure it's the best way of doing it, but this is what I do (I'm using a DataSet, it is only mildly different with a SQLDataReader):
Dim myDS as DataSet
' Fill myDS here
Dim myDR as DataRow
myDropDownList.Items.Add(new ListItem("All"))
For Each myDR in myDS.Tables(0).Rows
myDropDownList.Items.Add(new ListItem(myDR.Items("ColumnNameOrIndexHere")))
Next
I do this because the obvious issue with using DataBind is that it flushes whatever data you already had in there. However, looking at the documentation for ListItems, it appears you can do this:
'Get data and bind it to myDropDownList (assuming you are already doing this)
myDropDownList.Items.Insert(0, new ListItem("All"))
The documentation for ListItemCollection in DropDownList (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwebuiwebcontrolslistitemcollectionmemberstopic.asp) might help if neither of these are what you are looking for.

// Bind the DDL to the datasource first...
DDL.DataValueField = "value-column-name-here";
DDL.DataTextField = "text-column-name-here";
DDL.DataSource = dataTable;
DDL.DataBind();

// Add the "ALL" selection at the 1st (#0) position...
DDL.Items.Insert(0, new ListItem("ALL", "ALL"));
NC...


I think the most quicker way is to populatethe ArrayList from the Database using the SqlDataReader (In case youare using SQL Server Database).
The first element of the ArrayList will be "All" which you can simply add like this:
ArrayList a = new ArrayList();
a.Add("All");
after that you use SqlDataReader to populate the ArrayList and finally bind the list to the DropDownList.
Let me know if you need to know more about this technique!

And just how could you possibly think that going through the process of creating an ArrayList out of the data and then binding the ArrayList to the DDL be faster and better than just binding the DDL directly to the data?
NC...

It all depends on how many rows are in the Database Table and how many you are inserting in the DataSet.

In what way? Creating the ArrayList would take more time regardless, even not taking into account the GC having to be called to discard it afterwards.
NC...

DataSet is a collection of DataTables, DataRows and DataColumns so does;nt that make DataSet more heavier than an ArrayList.

Why wouldn't you just use the DataReader as the data source?
DDL.DataValueField = "value-column-name-here";
DDL.DataTextField = "text-column-name-here";
DDL.DataSource = dataReader;
DDL.DataBind();

// Add the "ALL" selection at the 1st (#0) position...
DDL.Items.Insert(0, new ListItem("ALL", "ALL"));
dataReader.Close();
Then you don't have the overhead of creating the ArrayList, or a collection of any kind. After all, you'll never need the ArrayList again after binding the DDL.
NC...


Ohh no no no!
Don't ever send the DataReader on the presentation layer. DataReaderworks while the connection is open so this means you are sending theopen connection on the presentation layer.
NEVER NEVER NEVER send the DataReader on the presentation layer. Thisis also like mixing the DataBase layer with presentation layer with noBLL in between.

azamsharp wrote:

Ohh no no no!
Don't ever send the DataReader on the presentation layer. DataReader works while the connection is open so this means you are sending the open connection on the presentation layer.
NEVER NEVER NEVER send the DataReader on the presentation layer. This is also like mixing the DataBase layer with presentation layer with no BLL in between.


Weren't you the one transferring the DataReader into an ArrayList? My data layer does nothing but produce DataTables and DataSets, so there are no Connection objects, Command objects, DataReader objects, etc in my presentation layer (nor in the entire application layer for that matter).
Here is the part that I disagree with you on:

azamsharp wrote:

I think the most quicker way is to populate the ArrayList from the Database using the SqlDataReader (In case you are using SQL Server Database).


It's no quicker to create an ArrayList than a DataTable from a DataReader (if you need the code, let me know and I'll post it). In fact, unless you create a custom class and a custom collection, you'll be very restricted with an ArrayList as you have no access to column names to attach the DataValueField and DataTextField properties of the DDL, so you'll have to use the same value for both.
NC...


>>Weren't you the one transferring the DataReader into an ArrayList?
Thats done in the business logic layer and not the presentation layer which you have demonstrated.


I would agree with azamsharp if it was an application with a static connection. However, in the case of a web page, your web server is maintaining the DB Connection either while you are populating the ArrayList from the DataReader or while performing the DataBind. No connection is maintained by the client computer, only the web server.

Well then we're talking the same thing then. My way uses a DataTable and your way uses an ArrayList. both constructed in the data layer.

The main problem, as I see it, is that using the ArrayList, you'll be restricted to one column (unless you create a custom class, stuffing that into the ArrayList, which will also take more time and code), since you have no access to column names in an ArrayList to attach to the DataValueField and DataTextField properties of the DDL, therefore, you'll have to use the same value for both.

NC...

Populate textbox from item selected in a drop down list

I am a newbie to .net so bear with me here.

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

populating a drop down list based on the date

Hi, I'm looking to populate a drop down list with the month and year for the next 12 months from the current date, codeing in C#

any help would be great, thanks

this will show the next 12 months in a textbox, not to hard for you to convert to a drop down list

 DateTime date =new DateTime(2007, 02, 11);for (int i = 1; i <= 12; i++) { txtOutput.Text += date.AddMonths(i).ToShortDateString() +"\r"; }

check out this code below... its working for me...

protected void Button2_Click(object sender, EventArgs e) {for (int iCount = 0; iCount < 12; iCount++) { DropDownList1.Items.Add(DateTime.Now.AddMonths(iCount + 1).ToString("MMMM"));if (DropDownList2.Items.FindByText(DateTime.Now.AddMonths(iCount + 1).ToString("yyyy")) ==null) DropDownList2.Items.Add(DateTime.Now.AddMonths(iCount + 1).ToString("yyyy")); } }

hope it helps./.

populating a Drop down list

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: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

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: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
>.
>

populating a drop down box with ms access information

what is the best way to populate a drop down box with a list of names in a database? i'm using webmatrix/asp.net and the names are in a field called "name" .

dim ConnString as string = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=MyDBPath;"
dim conn As System.Data.OleDb.OleDbConnection(ConnString)
dim cmd As New OleDb.OleDbCommand()
dim dr as OleDb.OleDbDataReader
cmd.connection = conn
cmd.CommandType = CommandType.Text
cmd.CommandText = "select id, name from mytable"
try
conn.open
dr = cmd.executereader() 'assuming dr is your datareader
myDropDownList.datasource = dr
myDropDownList.DataTextField = "name"
myDropDownList.DataValueField = "id" 'example of assinging a value field too
myDropDownList.Databind()
finally
conn.close
end try

This is an example using a datareader for quick access and ideal for dropdownlists. You will see examples using datasets too but this just happens to be my preference from a performance point of view.

populating a drop down list with information from a database

Hello,
I am using C# and want to dynamically populate a drop down list with information from my database. I can do this effectively by data binding to the drop down list.

customerInfo.DataSource = aDataSet;
customerInfo.DataValueField = "licence_No";
customerInfo.DataTextField = "licence_No";
customerInfo.DataBind();

customer.Info is the name of my DDL. This does populate my DDL. However there is a big problem. If I try and get the selectedItem value from the DDL it is always equal to the first item in DDL, and therefore my DDL is useless.
Any suggestions, its been causing me alot of problems.Post the code you are using to get the selectedItem. Also, where in your code are you trying to get the selectedItem - after a certain event? When is the DropDownList populated? It probably should be populated once, when ! Page.IsPostBack()...

cjmaxey
The code I am using to get the selected item is:


string selection = customerInfo.SelectedItem.ToString();

I am trying to get the selected item when a button is clicked. The drop down list is populated on page load.
Thanks for the help.
shannon_rider,

Be sure that the Dropdownlist is populated within Page_Load() within the following:


if ( ! Page.IsPostBack() )
{
// populate database
} // end if - Not Page PostBack

It may be that that the DropDownList is getting re-populated before the SelectedItem is found and, therefore, being reset to the first item.

Also, you may want to use one of the following depending on whether you want the text or the value (in your case, I believe they are the same):


string selection = customerInfo.SelectedItem.Value.ToString();
string selection = customerInfo.SelectedItem.Text.ToString();

Hope this helps,

cjmaxey
Thanks,
That advice has worked. I appreciate you taking the time to help.
I'll take that lesson on board.

Populating a Drop Down List using a SQL Stored Procedure

Hello All
I posted this question yesterday but I do not see it in the list, and I cannot search and locate it.

I am rather new to coding in ASP.NET. However, I have been coding with Classic ASP for many years. Please be patient with me and my seemingly simple questions

I am in need of some help with Populating a Drop Down List is ASp.NET using C#. I want to be able to populate a drop down list with the ID as the value and the Text as the text shown by calling a SQL stored procedure. If possible, can you give me an example and comment what the steps are.

After much searching yesterday, I found a good example using access. But this is not what I needed. However, it did get me started with the concept.

And another question. How would I code to see the value choosen? My web forms contain mostly drop down list for items such as: state names, postal codes, area codes, dates, times, etc... Just about anything that I can use a DDL, I use it. Saves so much in the error checking.

Thank you in advance for your time.
Andrew
SQL DBATheres a few steps involved in getting data to be present on a page.

First for your application you'll need to create a DataReader object to interact with your SQLCommand which is your stored procedure. (research on how to implement a DataReader)

Then once you have data in your DataReader, you can bind it do the DDL like so:

ddl.DataSource = YourDataReaderName
ddl.DataValueField = "FieldNameofYourChoice" from your DataReader
ddl.DataTextFiled = "FiledNameofYourchoice" from your DataReader
ddl.DataBind

Basically that's it
Thank you
I was hoping to get more of a step by step instruction.
I am having alot of trouble making the database connection. I am seeing so many different types and ways of doing the same thing, that it is getting very confusing. Some inside the aspx page and some in the cs page. I would like to use the code behind cs page.

Any sites out there tell how to do that? And give good examples.

I used to use that same signature many years ago.

Thanks
Andrew

Populating a dropdown control

I am trying to populate a drop down on a form with the contents of a
recordset and I am getting the following values in the dropdown
System.Data.DataRowView and not the expected content that should be
appearing in there. I have stepped through the code in debug mode and
examine the value of the recordset, and the right values seem to be there.
Any idea what is causing this and how to fix it so that it does not show up
like this?
.ResetParameters()
.AddParameter("iMRN", OleDb.OleDbType.Integer, ParameterDirection.Input,
ctlHeader.PatientData("PatientMRN"))
'Pull back the list of encounters for the selected patient
If .Execute(.genuSql.StoreProcSelect, "selPatient_Billing") Then
Dim oRow As DataRow
oData = .DbData_DataTable
If .DbData_DataTable.Rows.Count > 0 Then
With drpEnc
.DataSource = oData
.DataBind()
.DataValueField = "id"
.DataTextField = "DateOfService"
End With
End If
Else
Throw New Exception(.ErrorMessage)
End If 'Encounter List
J.Daly
structure:interactive
Ph: 616-364-7423
Fx: 616-364-6941
http://www.structureinteractive.comSe the DataText and DataVauleField properties BEFORE the DataBind().
DataBind() binds your source to your control, setting what to bind after
doesn't work :)
Karl
"Irishmaninusa"
<jdaly@.structuctureinteractive.com.takemeoffifyouwantoemailme> wrote in
message news:u3boxQ3iEHA.2992@.TK2MSFTNGP12.phx.gbl...
> I am trying to populate a drop down on a form with the contents of a
> recordset and I am getting the following values in the dropdown
> System.Data.DataRowView and not the expected content that should be
> appearing in there. I have stepped through the code in debug mode and
> examine the value of the recordset, and the right values seem to be there.
> Any idea what is causing this and how to fix it so that it does not show
up
> like this?
>
>
> .ResetParameters()
> .AddParameter("iMRN", OleDb.OleDbType.Integer, ParameterDirection.Input,
> ctlHeader.PatientData("PatientMRN"))
> 'Pull back the list of encounters for the selected patient
> If .Execute(.genuSql.StoreProcSelect, "selPatient_Billing") Then
> Dim oRow As DataRow
> oData = .DbData_DataTable
>
> If .DbData_DataTable.Rows.Count > 0 Then
> With drpEnc
> .DataSource = oData
> .DataBind()
> .DataValueField = "id"
> .DataTextField = "DateOfService"
> End With
> End If
> Else
> Throw New Exception(.ErrorMessage)
> End If 'Encounter List
>
> --
> J.Daly
> structure:interactive
> Ph: 616-364-7423
> Fx: 616-364-6941
> http://www.structureinteractive.com
>
>
I thought I had did that before and it still didn't work, but I tried it
again and this time it work. Now I have different issue, the stored
procedure I call pulls back date values in order, where the most recent date
is at the top and it goes back in order.
7/28/2004
7/1/2004
6/30/2004
This is the where the stored procedure pulls back the dates, which is
correct. However in the drop down it is being displayed as
7/28/2004
6/30/2004
7/1/2004
Why would this be like this?
"Karl" <karl REMOVE @. REMOVE openmymind REMOVEMETOO . ANDME net> wrote in
message news:OzuKbe3iEHA.636@.TK2MSFTNGP12.phx.gbl...
> Se the DataText and DataVauleField properties BEFORE the DataBind().
> DataBind() binds your source to your control, setting what to bind after
> doesn't work :)
> Karl
> "Irishmaninusa"
> <jdaly@.structuctureinteractive.com.takemeoffifyouwantoemailme> wrote in
> message news:u3boxQ3iEHA.2992@.TK2MSFTNGP12.phx.gbl...
there.
> up
>
I honestly don't know. I can see that you are using OLEdbClient which I'm
no expert at. Are these Date fields or string/varchar fields? you may want
to start a new thread asking this question and identifying the
database/query/schema so that someone better suited will help.
Karl
"Irishmaninusa"
<jdaly@.structuctureinteractive.com.takemeoffifyouwantoemailme> wrote in
message news:e2sIEo3iEHA.536@.TK2MSFTNGP11.phx.gbl...
> I thought I had did that before and it still didn't work, but I tried it
> again and this time it work. Now I have different issue, the stored
> procedure I call pulls back date values in order, where the most recent
date
> is at the top and it goes back in order.
> 7/28/2004
> 7/1/2004
> 6/30/2004
> This is the where the stored procedure pulls back the dates, which is
> correct. However in the drop down it is being displayed as
>
> 7/28/2004
> 6/30/2004
> 7/1/2004
> Why would this be like this?
> "Karl" <karl REMOVE @. REMOVE openmymind REMOVEMETOO . ANDME net> wrote in
> message news:OzuKbe3iEHA.636@.TK2MSFTNGP12.phx.gbl...
> there.
show
ParameterDirection.Input,
>
Thanks Karl, I will see what turns up. Thank you for your help to my earlier
issue.
"Karl" <karl REMOVE @. REMOVE openmymind REMOVEMETOO . ANDME net> wrote in
message news:umG6hJ4iEHA.1376@.TK2MSFTNGP11.phx.gbl...
> I honestly don't know. I can see that you are using OLEdbClient which I'm
> no expert at. Are these Date fields or string/varchar fields? you may
want
> to start a new thread asking this question and identifying the
> database/query/schema so that someone better suited will help.
> Karl
> "Irishmaninusa"
> <jdaly@.structuctureinteractive.com.takemeoffifyouwantoemailme> wrote in
> message news:e2sIEo3iEHA.536@.TK2MSFTNGP11.phx.gbl...
> date
in
after
in
and
> show
> ParameterDirection.Input,
>

Populating a dropdown control

I am trying to populate a drop down on a form with the contents of a
recordset and I am getting the following values in the dropdown

System.Data.DataRowView and not the expected content that should be
appearing in there. I have stepped through the code in debug mode and
examine the value of the recordset, and the right values seem to be there.

Any idea what is causing this and how to fix it so that it does not show up
like this?

..ResetParameters()

..AddParameter("iMRN", OleDb.OleDbType.Integer, ParameterDirection.Input,
ctlHeader.PatientData("PatientMRN"))

'Pull back the list of encounters for the selected patient

If .Execute(.genuSql.StoreProcSelect, "selPatient_Billing") Then

Dim oRow As DataRow

oData = .DbData_DataTable

If .DbData_DataTable.Rows.Count > 0 Then

With drpEnc

..DataSource = oData

..DataBind()

..DataValueField = "id"

..DataTextField = "DateOfService"

End With

End If

Else

Throw New Exception(.ErrorMessage)

End If 'Encounter List

--
J.Daly
structure:interactive
Ph: 616-364-7423
Fx: 616-364-6941

http://www.structureinteractive.comSe the DataText and DataVauleField properties BEFORE the DataBind().

DataBind() binds your source to your control, setting what to bind after
doesn't work :)

Karl

"Irishmaninusa"
<jdaly@.structuctureinteractive.com.takemeoffifyouwa ntoemailme> wrote in
message news:u3boxQ3iEHA.2992@.TK2MSFTNGP12.phx.gbl...
> I am trying to populate a drop down on a form with the contents of a
> recordset and I am getting the following values in the dropdown
> System.Data.DataRowView and not the expected content that should be
> appearing in there. I have stepped through the code in debug mode and
> examine the value of the recordset, and the right values seem to be there.
> Any idea what is causing this and how to fix it so that it does not show
up
> like this?
>
>
> .ResetParameters()
> .AddParameter("iMRN", OleDb.OleDbType.Integer, ParameterDirection.Input,
> ctlHeader.PatientData("PatientMRN"))
> 'Pull back the list of encounters for the selected patient
> If .Execute(.genuSql.StoreProcSelect, "selPatient_Billing") Then
> Dim oRow As DataRow
> oData = .DbData_DataTable
>
> If .DbData_DataTable.Rows.Count > 0 Then
> With drpEnc
> .DataSource = oData
> .DataBind()
> .DataValueField = "id"
> .DataTextField = "DateOfService"
> End With
> End If
> Else
> Throw New Exception(.ErrorMessage)
> End If 'Encounter List
>
> --
> J.Daly
> structure:interactive
> Ph: 616-364-7423
> Fx: 616-364-6941
> http://www.structureinteractive.com
I thought I had did that before and it still didn't work, but I tried it
again and this time it work. Now I have different issue, the stored
procedure I call pulls back date values in order, where the most recent date
is at the top and it goes back in order.

7/28/2004
7/1/2004
6/30/2004

This is the where the stored procedure pulls back the dates, which is
correct. However in the drop down it is being displayed as

7/28/2004
6/30/2004
7/1/2004

Why would this be like this?

"Karl" <karl REMOVE @. REMOVE openmymind REMOVEMETOO . ANDME net> wrote in
message news:OzuKbe3iEHA.636@.TK2MSFTNGP12.phx.gbl...
> Se the DataText and DataVauleField properties BEFORE the DataBind().
> DataBind() binds your source to your control, setting what to bind after
> doesn't work :)
> Karl
> "Irishmaninusa"
> <jdaly@.structuctureinteractive.com.takemeoffifyouwa ntoemailme> wrote in
> message news:u3boxQ3iEHA.2992@.TK2MSFTNGP12.phx.gbl...
> > I am trying to populate a drop down on a form with the contents of a
> > recordset and I am getting the following values in the dropdown
> > System.Data.DataRowView and not the expected content that should be
> > appearing in there. I have stepped through the code in debug mode and
> > examine the value of the recordset, and the right values seem to be
there.
> > Any idea what is causing this and how to fix it so that it does not show
> up
> > like this?
> > .ResetParameters()
> > .AddParameter("iMRN", OleDb.OleDbType.Integer, ParameterDirection.Input,
> > ctlHeader.PatientData("PatientMRN"))
> > 'Pull back the list of encounters for the selected patient
> > If .Execute(.genuSql.StoreProcSelect, "selPatient_Billing") Then
> > Dim oRow As DataRow
> > oData = .DbData_DataTable
> > If .DbData_DataTable.Rows.Count > 0 Then
> > With drpEnc
> > .DataSource = oData
> > .DataBind()
> > .DataValueField = "id"
> > .DataTextField = "DateOfService"
> > End With
> > End If
> > Else
> > Throw New Exception(.ErrorMessage)
> > End If 'Encounter List
> > --
> > J.Daly
> > structure:interactive
> > Ph: 616-364-7423
> > Fx: 616-364-6941
> > http://www.structureinteractive.com
I honestly don't know. I can see that you are using OLEdbClient which I'm
no expert at. Are these Date fields or string/varchar fields? you may want
to start a new thread asking this question and identifying the
database/query/schema so that someone better suited will help.

Karl

"Irishmaninusa"
<jdaly@.structuctureinteractive.com.takemeoffifyouwa ntoemailme> wrote in
message news:e2sIEo3iEHA.536@.TK2MSFTNGP11.phx.gbl...
> I thought I had did that before and it still didn't work, but I tried it
> again and this time it work. Now I have different issue, the stored
> procedure I call pulls back date values in order, where the most recent
date
> is at the top and it goes back in order.
> 7/28/2004
> 7/1/2004
> 6/30/2004
> This is the where the stored procedure pulls back the dates, which is
> correct. However in the drop down it is being displayed as
>
> 7/28/2004
> 6/30/2004
> 7/1/2004
> Why would this be like this?
> "Karl" <karl REMOVE @. REMOVE openmymind REMOVEMETOO . ANDME net> wrote in
> message news:OzuKbe3iEHA.636@.TK2MSFTNGP12.phx.gbl...
> > Se the DataText and DataVauleField properties BEFORE the DataBind().
> > DataBind() binds your source to your control, setting what to bind after
> > doesn't work :)
> > Karl
> > "Irishmaninusa"
> > <jdaly@.structuctureinteractive.com.takemeoffifyouwa ntoemailme> wrote in
> > message news:u3boxQ3iEHA.2992@.TK2MSFTNGP12.phx.gbl...
> > > I am trying to populate a drop down on a form with the contents of a
> > > recordset and I am getting the following values in the dropdown
> > > > System.Data.DataRowView and not the expected content that should be
> > > appearing in there. I have stepped through the code in debug mode and
> > > examine the value of the recordset, and the right values seem to be
> there.
> > > > Any idea what is causing this and how to fix it so that it does not
show
> > up
> > > like this?
> > > > > > > > .ResetParameters()
> > > > .AddParameter("iMRN", OleDb.OleDbType.Integer,
ParameterDirection.Input,
> > > ctlHeader.PatientData("PatientMRN"))
> > > > 'Pull back the list of encounters for the selected patient
> > > > If .Execute(.genuSql.StoreProcSelect, "selPatient_Billing") Then
> > > > Dim oRow As DataRow
> > > > oData = .DbData_DataTable
> > > > > > If .DbData_DataTable.Rows.Count > 0 Then
> > > > With drpEnc
> > > > .DataSource = oData
> > > > .DataBind()
> > > > .DataValueField = "id"
> > > > .DataTextField = "DateOfService"
> > > > End With
> > > > End If
> > > > Else
> > > > Throw New Exception(.ErrorMessage)
> > > > End If 'Encounter List
> > > > > --
> > > J.Daly
> > > structure:interactive
> > > Ph: 616-364-7423
> > > Fx: 616-364-6941
> > > > http://www.structureinteractive.com
> > >
Thanks Karl, I will see what turns up. Thank you for your help to my earlier
issue.

"Karl" <karl REMOVE @. REMOVE openmymind REMOVEMETOO . ANDME net> wrote in
message news:umG6hJ4iEHA.1376@.TK2MSFTNGP11.phx.gbl...
> I honestly don't know. I can see that you are using OLEdbClient which I'm
> no expert at. Are these Date fields or string/varchar fields? you may
want
> to start a new thread asking this question and identifying the
> database/query/schema so that someone better suited will help.
> Karl
> "Irishmaninusa"
> <jdaly@.structuctureinteractive.com.takemeoffifyouwa ntoemailme> wrote in
> message news:e2sIEo3iEHA.536@.TK2MSFTNGP11.phx.gbl...
> > I thought I had did that before and it still didn't work, but I tried it
> > again and this time it work. Now I have different issue, the stored
> > procedure I call pulls back date values in order, where the most recent
> date
> > is at the top and it goes back in order.
> > 7/28/2004
> > 7/1/2004
> > 6/30/2004
> > This is the where the stored procedure pulls back the dates, which is
> > correct. However in the drop down it is being displayed as
> > 7/28/2004
> > 6/30/2004
> > 7/1/2004
> > Why would this be like this?
> > "Karl" <karl REMOVE @. REMOVE openmymind REMOVEMETOO . ANDME net> wrote
in
> > message news:OzuKbe3iEHA.636@.TK2MSFTNGP12.phx.gbl...
> > > Se the DataText and DataVauleField properties BEFORE the DataBind().
> > > > DataBind() binds your source to your control, setting what to bind
after
> > > doesn't work :)
> > > > Karl
> > > > "Irishmaninusa"
> > > <jdaly@.structuctureinteractive.com.takemeoffifyouwa ntoemailme> wrote
in
> > > message news:u3boxQ3iEHA.2992@.TK2MSFTNGP12.phx.gbl...
> > > > I am trying to populate a drop down on a form with the contents of a
> > > > recordset and I am getting the following values in the dropdown
> > > > > > System.Data.DataRowView and not the expected content that should be
> > > > appearing in there. I have stepped through the code in debug mode
and
> > > > examine the value of the recordset, and the right values seem to be
> > there.
> > > > > > Any idea what is causing this and how to fix it so that it does not
> show
> > > up
> > > > like this?
> > > > > > > > > > > > > > .ResetParameters()
> > > > > > .AddParameter("iMRN", OleDb.OleDbType.Integer,
> ParameterDirection.Input,
> > > > ctlHeader.PatientData("PatientMRN"))
> > > > > > 'Pull back the list of encounters for the selected patient
> > > > > > If .Execute(.genuSql.StoreProcSelect, "selPatient_Billing") Then
> > > > > > Dim oRow As DataRow
> > > > > > oData = .DbData_DataTable
> > > > > > > > > > If .DbData_DataTable.Rows.Count > 0 Then
> > > > > > With drpEnc
> > > > > > .DataSource = oData
> > > > > > .DataBind()
> > > > > > .DataValueField = "id"
> > > > > > .DataTextField = "DateOfService"
> > > > > > End With
> > > > > > End If
> > > > > > Else
> > > > > > Throw New Exception(.ErrorMessage)
> > > > > > End If 'Encounter List
> > > > > > > > --
> > > > J.Daly
> > > > structure:interactive
> > > > Ph: 616-364-7423
> > > > Fx: 616-364-6941
> > > > > > http://www.structureinteractive.com
> > > > > > > >

Friday, March 16, 2012

populating asp:dropdownlist programmatically

I need to display a drop down list which holds up to 250 listitems.

I'd like to create this programmatically rather than have to hardcode it
into the page.

For example

<asp:DropDownList id="numYears" runat="server" name="numYears">
<asp:ListItem Value="0" Text="0 years" Selected="true" />
<asp:ListItem Value="1" Text="1 year"/>
<asp:ListItem Value="2" Text="2 year"/>
<asp:ListItem Value="2" Text="2 year"/>
<asp:ListItem Value="3" Text etc.......... up to 250 years

Thanks in advance..

Simon AmesHi,

put the DDL declaration at the Page (or create it in code just as you see
better).

<asp:DropDownList ID="ddl1" Runat="server">
</asp:DropDownList
Then say in Page_Load:

= = =
if(!Page.IsPostBack)
{
for(int i=0;i<251;i++)
{
ListItem litem=new ListItem(i.ToString() + " years",i.ToString());
ddl1.Items.Add(litem);
}
ddl1.SelectedIndex =0;
}
= = =

--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist

"amessimon" <amessimon@.hotmail.com> wrote in message
news:e1ZyKV4AEHA.744@.TK2MSFTNGP10.phx.gbl...
I need to display a drop down list which holds up to 250 listitems.

I'd like to create this programmatically rather than have to hardcode it
into the page.

For example

<asp:DropDownList id="numYears" runat="server" name="numYears">
<asp:ListItem Value="0" Text="0 years" Selected="true" />
<asp:ListItem Value="1" Text="1 year"/>
<asp:ListItem Value="2" Text="2 year"/>
<asp:ListItem Value="2" Text="2 year"/>
<asp:ListItem Value="3" Text etc.......... up to 250 years

Thanks in advance..

Simon Ames
Hello Simon
"amessimon" <amessimon@.hotmail.com> schrieb im Newsbeitrag
news:e1ZyKV4AEHA.744@.TK2MSFTNGP10.phx.gbl...
> I need to display a drop down list which holds up to 250 listitems.
> I'd like to create this programmatically rather than have to hardcode it
> into the page.
> For example
> <asp:DropDownList id="numYears" runat="server" name="numYears">
> <asp:ListItem Value="0" Text="0 years" Selected="true" />
> <asp:ListItem Value="1" Text="1 year"/>
> <asp:ListItem Value="2" Text="2 year"/>
> <asp:ListItem Value="2" Text="2 year"/>
> <asp:ListItem Value="3" Text etc.......... up to 250 years

for (int i=0; i<=250; i++)

{

numYears.Items.Add(i.ToString());

}

mfg simon g.

Populating Drop Down List

Hi,

I have a drop down list which is bound to a database field and is populated from so. However I want to add 1 of my own items to the drop down list no matter what is in the database. Is this possible?

ThanksYes. You can use the .Items.Add or .Items.Insert to add items to the dropdownlist. Just be sure to do this after you bind your data, because the bind will remove all items from the list.

hope this helps,
sivilian
Thanks very much, solved my problem.
Well the method is working but how we can set the additional item at the top, for example set "Select one State" on top of my drop down.

Thanks
Hello, try that in the page_load:

ddl.Items.Insert(new ListItem("text",value"),0);

regards
Thanks for you time,

Overload resolution failed because no accessible 'Insert' can be called with these arguments:

the aforsaid error return on line

AltShippingAdd.Items.Insert(new ListItem("Carbon", "C"),0);

Thanks in Advance
Hello,

this working fine, i think there is some problem in syntex.

AltShippingAdd.Items.Insert(0, New ListItem("Select One"))

the above statement is working fine but we can't able to define the value of that item is there a way to define the value of this item.

Thanks.
oh! in advance.
Hello, maybe you are right, I messed up with the syntax. but try to have:

AltShippingAdd.Items.Inert(0,new ListItem("Select One","1"))

regards
Thanks Bilal
It works fine
I am glad I was able to help you out my friend. For any further help, please dont hesitate to contact me here at the forums.

regards

Populating Drop down box value

Hello,

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

Hello,
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 + "'";