User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the ASP.NET section within the Web Development category of DaniWeb, a massive community of 456,528 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,741 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our ASP.NET advertiser: Lunarpages ASP Web Hosting
Views: 964 | Replies: 7
Reply
Join Date: Oct 2007
Posts: 5
Reputation: joshireddy.p is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
joshireddy.p joshireddy.p is offline Offline
Newbie Poster

Question reg OnlineExam Project

  #1  
Oct 7th, 2007
hi

i am joshi. i got a problem in my project, ie i have declared 50 labels with a name q1,q2....q50 now i want to call these labels with a use of for loop..... but how

please help me....
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Apr 2007
Posts: 262
Reputation: greeny_1984 is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 10
greeny_1984's Avatar
greeny_1984 greeny_1984 is offline Offline
Posting Whiz in Training

Re: reg OnlineExam Project

  #2  
Oct 8th, 2007
hii,
iam giving an example to display dynamically two labels.hope it is usefull.
if u have already have 5 labels in u r page but u want to display only 2 labels ,then this function is usefull
label1,label2 be u r label ids in the page

dim lbl as string
dim l as label
for 1=0 to 1
lbl="label"& convert.tostring(i)
l=page.findcontrol(lbl)
l.visible=true
next
Reply With Quote  
Join Date: Oct 2007
Posts: 5
Reputation: joshireddy.p is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
joshireddy.p joshireddy.p is offline Offline
Newbie Poster

Re: reg OnlineExam Project

  #3  
Oct 9th, 2007
hi
thq for your reply...
if i wrote l=page.findcontrol(lbl), i am getting an error that Error Cannot implicitly convert type 'System.Web.UI.Control' to 'System.Web.UI.WebControls.Label'. An explicit conversion exists (are you missing a cast?)

how can i slove this problem
please reply me.....
Reply With Quote  
Join Date: Apr 2007
Posts: 262
Reputation: greeny_1984 is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 10
greeny_1984's Avatar
greeny_1984 greeny_1984 is offline Offline
Posting Whiz in Training

Re: reg OnlineExam Project

  #4  
Oct 9th, 2007
hii,
did u declare l as label
dim l as label
thats the only reason i see for getting the error.the code i gave u was being used by me in my project .
Reply With Quote  
Join Date: Apr 2007
Posts: 262
Reputation: greeny_1984 is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 10
greeny_1984's Avatar
greeny_1984 greeny_1984 is offline Offline
Posting Whiz in Training

Re: reg OnlineExam Project

  #5  
Oct 9th, 2007
hii,
i have figured it out.since u have declared starting from q1 ,the code i gave works from qo,so here is the correct code
Dim i As Integer
Dim lbl As Label
Dim b As String
For i = 0 To 1
b = "label" & Convert.ToString(i + 1)
lbl = Page.FindControl(b)
lbl.Visible = True
Next
Reply With Quote  
Join Date: Oct 2007
Posts: 5
Reputation: joshireddy.p is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
joshireddy.p joshireddy.p is offline Offline
Newbie Poster

Re: reg OnlineExam Project

  #6  
Oct 10th, 2007
hi
thanks for your reply ones again..
i have wrote same code but i am getting an error that "object reference is not set to an instance"
Reply With Quote  
Join Date: Sep 2007
Posts: 1,058
Reputation: SheSaidImaPregy is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 61
SheSaidImaPregy SheSaidImaPregy is offline Offline
Veteran Poster

Re: reg OnlineExam Project

  #7  
Oct 10th, 2007
You should not have to find the labels unless they are nested in another control like a datalist, grid, or repeater, etc. Try telling us what you want to do in this loop.

Oh, and the reason why his code isn't working for you is due to a few flaws. The below code is suited for you:
Public Function LoopingTheLbls()
Dim i As Integer
Dim lbl As Label
Dim b As String
For i = 0 To 49
b = "q" & Convert.ToString(i + 1)
lbl = Page.FindControl(b)
lbl.Text = "Help I am control " & (i + 1)
next 
End Function
Last edited by SheSaidImaPregy : Oct 10th, 2007 at 2:51 am.
Reply With Quote  
Join Date: Oct 2007
Posts: 5
Reputation: joshireddy.p is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
joshireddy.p joshireddy.p is offline Offline
Newbie Poster

Re: reg OnlineExam Project

  #8  
Oct 14th, 2007
tq
i got it.
i know what the mistake i am doing.
thq ones again
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb ASP.NET Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the ASP.NET Forum

All times are GMT -4. The time now is 4:22 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC