473,320 Members | 1,707 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

How to moving a list to codebehind?

Paul Johnson
Hi,

I have some markup on a page which I need to move to a code behind and I'm not quite sure how to do it

An example is this

Expand|Select|Wrap|Line Numbers
  1. <asp:DropDownList ID="YearList" runat="server">
  2.          <asp:ListItem Value="1940" Title="1940" />
  3.          <asp:ListItem Value="1950" Title="1950" />
  4.          <asp:ListItem Value="1960" Title="1960" />
  5.          <asp:ListItem Value="1970" Title="1970" />
  6.  
Would the codebehind become

Expand|Select|Wrap|Line Numbers
  1. With YearList
  2.   .Value(0)="1940"
  3.   .Text(0)="1940"
  4. End With
  5.  
or would it be something else?

Thanks

PJ
Jan 25 '11 #1

✓ answered by Dotneticus

You could use:

Dropdownlist.Items.Add(New ListItem("1940", "1940")) - If the value is different from the displayed item.

If they are the same, you can use:

Dropdownlist.Items.Add("1940")

3 1436
Will the list values be coming from a database or just will it be just a predefined list?
Jan 25 '11 #2
predefined
Jan 25 '11 #3
You could use:

Dropdownlist.Items.Add(New ListItem("1940", "1940")) - If the value is different from the displayed item.

If they are the same, you can use:

Dropdownlist.Items.Add("1940")
Jan 25 '11 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Allan M. | last post by:
I have a series of select boxes that must be populated client side, because they interact with each other. The design specification calls for these boxes to be updated without having to make a...
5
by: Dude | last post by:
I migrated to 1.1 Changes I make to the aspx page are fine, changes to codebehind page are not reflected after I compile and view in the browser. I deleted all the files from the cache directory on...
12
by: Karl Hungus | last post by:
If I use a code behind class for an aspx page, what is the best way to get data from the codebehind class into my aspx page? I know about databinding, but is there a more basic way of just...
4
by: Poppy | last post by:
(VS.net 2002) I moved an aspx file and code behind from one folder to another in Visual Studio and when I compile/run the application the compiler keeps saying that it cannot find the code...
8
by: Robson Machado | last post by:
Dear friens, Does anybody knows how to move controls (images, textboxes, buttons, etc..) using CodeBehind? Regards,
4
by: Bob P. | last post by:
Hello, I have a page with: * two side-by-side asp:listboxes and two arrow asp:buttons allowing users to add/remove email addresses between them -- very much like Outlook, where you have the...
2
by: nobody | last post by:
Why doesn't the casting of "e.Item.DataI­tem" as a "DataRow" (or even a "DataRowView" as in other online examples) work? I would love to get this type of code to work with my code that uses a...
7
by: Alex | last post by:
Hi all, I've been writing in ColdFusion for about 6 years now, and now that we've installed a Sharepoint Portal Server I'm finding that I need to use ASP.Net to make database calls. I'm finding...
6
by: Britney | last post by:
hi I want to create an age drop-down list. values for age is from 1 to 100. It seems so easy but I have to write over 100 lines of codes (100 listitems) Is there a simple way to achieve the same...
3
by: MartyNg | last post by:
I have been looking online for pointers, and read mixed things. I was hoping if I post direct questions here, I could get some solid answers. I work for a small company with less than 10 web...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.