Welcome to Dream.In.Code
Getting Help is Easy!

Join 136,542 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,821 people online right now. Registration is fast and FREE... Join Now!




Using variable as Label control ID

 
Reply to this topicStart new topic

Using variable as Label control ID, How to use a variable, extracted from a datareader, as an ID of a labe

Elven
13 Aug, 2008 - 05:05 AM
Post #1

New D.I.C Head
*

Joined: 13 Aug, 2008
Posts: 7

Hi,

I am looking into a way to shorten my code and make it simpler. At the moment code looks like
CODE
                     while (dr.Read())
                     {
                         SwString = dr["Page"].ToString();
                         switch (SwString)
                         {
                         case "Home":
                         Temp = dr["PageText"].ToString();
                         HomeLbl.Text = Temp.Replace("</br>", Convert.ToString((char)13));
                                 break;
                         case "About":
                                 Temp = dr["PageText"].ToString();
                                 AboutLbl.Text = Temp.Replace("</br>", Convert.ToString((char)13));
                                 break;


With many more cases to go. I am looking into a way to simply use a field called "PageText" as a label ID. Aka I want to fill in a label called "AboutLbl" with a data from the field "PageText" where field "Page" equals "About".

Can I do something like:
CODE
while (dr.Read())
                                  SwString = dr["Page"].ToString();
                                  Temp = dr["PageText"].ToString();
                         %SwString%Lbl.Text = Temp.Replace("</br>", Convert.ToString((char)13));
                                


This post has been edited by Elven: 14 Aug, 2008 - 12:23 AM
User is offlineProfile CardPM
+Quote Post

Elven
RE: Using Variable As Label Control ID
14 Aug, 2008 - 12:25 AM
Post #2

New D.I.C Head
*

Joined: 13 Aug, 2008
Posts: 7

I have noticed that this is in the wrong forum. Could a moderator please move this to ASP.Net?

I am sorry for the trouble/
User is offlineProfile CardPM
+Quote Post

Jayman
RE: Using Variable As Label Control ID
14 Aug, 2008 - 05:18 PM
Post #3

Student of Life
Group Icon

Joined: 26 Dec, 2005
Posts: 6,947



Thanked: 42 times
Dream Kudos: 500
Expert In: C#, VB.NET, Java

My Contributions
As requested, moved to ASP.NET.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/2/08 10:36PM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month