473,386 Members | 1,647 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,386 software developers and data experts.

For Each Loop in ASP.NET 2.0

Hello,

I want to create label and checkbox for every member in the database
table.

How can I do that?

I tried:

Dim x as integer

For Each x In ds.Tables(0).Rows.Count
.... code here
Next
But it didnt work, giving an error:

Error 1 Expression is of type 'Integer', which is not a collection
type.

also how can I code creating a new checkbox and label for every x
in the table?

Aug 1 '06 #1
4 14114

Dot Net Daddy napisal(a):
Hello,

I want to create label and checkbox for every member in the database
table.

How can I do that?

I tried:

Dim x as integer

For Each x In ds.Tables(0).Rows.Count
.... code here
Next
But it didnt work, giving an error:

Error 1 Expression is of type 'Integer', which is not a collection
type.

also how can I code creating a new checkbox and label for every x
in the table?
Hi,

First of all, you use For Each ... In ... to iterate through a
collection of items. In your code x's type should be DataRow and you
should interate through collection of rows like that:

dim x as DataRow

For Each x In ds.Tables(0).Rows
....
Next

or
Dim RowNumber as Integer=ds.Tables(0).Rows.Count

for i as integer=1 to RowNumber
....
Next
Secondly, I don't think creating many Labels and checkboxes is good
idea. If you want to show data from dataset it's beter to use GridView.
You can have there for example CheckBox field.

regards,
sweet_dreams

Aug 1 '06 #2
Thank you for your help.
I tried to do it with GridView but I couldn't, (I am a newbie)

For example, say I want to assign a label the value in the gridview
that has been selected. I tried
Protected Sub GridView1_SelectedIndexChanged(ByVal sender As
Object, ByVal e As System.EventArgs) Handles
GridView1.SelectedIndexChanged
Label1.Text = GridView1.SelectedRow.Cells(0).ToString
End Sub

when I select a row Label1 is assigned the value:
"System.Web.UI.WebControls.DataControlFieldCel l"

actually I want to assign the value in the selected row to an imageURL.
as far as I know GridView should be able to do it. but I couldnt get it
done.

thanks again for your help...
sweet_dreams wrote:
Dot Net Daddy napisal(a):
Hello,

I want to create label and checkbox for every member in the database
table.

How can I do that?

I tried:

Dim x as integer

For Each x In ds.Tables(0).Rows.Count
.... code here
Next
But it didnt work, giving an error:

Error 1 Expression is of type 'Integer', which is not a collection
type.

also how can I code creating a new checkbox and label for every x
in the table?

Hi,

First of all, you use For Each ... In ... to iterate through a
collection of items. In your code x's type should be DataRow and you
should interate through collection of rows like that:

dim x as DataRow

For Each x In ds.Tables(0).Rows
...
Next

or
Dim RowNumber as Integer=ds.Tables(0).Rows.Count

for i as integer=1 to RowNumber
...
Next
Secondly, I don't think creating many Labels and checkboxes is good
idea. If you want to show data from dataset it's beter to use GridView.
You can have there for example CheckBox field.

regards,
sweet_dreams
Aug 1 '06 #3
Protected Sub GridView1_SelectedIndexChanged(ByVal sender As
Object, ByVal e As System.EventArgs) Handles
GridView1.SelectedIndexChanged
Label1.Text = GridView1.SelectedRow.Cells(0).ToString
End Sub

when I select a row Label1 is assigned the value:
"System.Web.UI.WebControls.DataControlFieldCel l"
Actualy I don't use ASP but I think that it should be like that:
Label1.Text = GridView1.SelectedRow.Cells(0).Value

Hope this helps.

regards,
sweet_dreams

Aug 1 '06 #4
There is no control like Cells.Value

thanks anyway for your help

sweet_dreams wrote:
Protected Sub GridView1_SelectedIndexChanged(ByVal sender As
Object, ByVal e As System.EventArgs) Handles
GridView1.SelectedIndexChanged
Label1.Text = GridView1.SelectedRow.Cells(0).ToString
End Sub

when I select a row Label1 is assigned the value:
"System.Web.UI.WebControls.DataControlFieldCel l"

Actualy I don't use ASP but I think that it should be like that:
Label1.Text = GridView1.SelectedRow.Cells(0).Value

Hope this helps.

regards,
sweet_dreams
Aug 1 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Charles Alexander | last post by:
Hello I am new to php & MySQL - I am trying to retrieve some records from a MySQL table and redisplay them. The data in list form looks like this: Sample_ID Marker_ID Variation ...
3
by: Anand Pillai | last post by:
This is for folks who are familiar with asynchronous event handling in Python using the asyncore module. If you have ever used the asyncore module, you will realize that it's event loop does not...
43
by: Gremlin | last post by:
If you are not familiar with the halting problem, I will not go into it in detail but it states that it is impossible to write a program that can tell if a loop is infinite or not. This is a...
5
by: Martin Schou | last post by:
Please ignore the extreme simplicity of the task :-) I'm new to C, which explains why I'm doing an exercise like this. In the following tripple nested loop: int digit1 = 1; int digit2 = 0;...
32
by: Toby Newman | last post by:
At the page: http://www.strath.ac.uk/IT/Docs/Ccourse/subsection3_8_3.html#SECTION0008300000000000000 or http://tinyurl.com/4ptzs the author warns: "The for loop is frequently used, usually...
2
by: Alex | last post by:
Compiler - Borland C++ 5.6.4 for Win32 Copyright (c) 1993, 2002 Borland Linker - Turbo Incremental Link 5.65 Copyright (c) 1997-2002 Borland Platform - Win32 (XP) Quite by accident I stumbled...
3
by: Ben R. | last post by:
In an article I was reading (http://www.ftponline.com/vsm/2005_06/magazine/columns/desktopdeveloper/), I read the following: "The ending condition of a VB.NET for loop is evaluated only once,...
32
by: cj | last post by:
When I'm inside a do while loop sometimes it's necessary to jump out of the loop using exit do. I'm also used to being able to jump back and begin the loop again. Not sure which language my...
16
by: Claudio Grondi | last post by:
Sometimes it is known in advance, that the time spent in a loop will be in order of minutes or even hours, so it makes sense to optimize each element in the loop to make it run faster. One of...
2
ADezii
by: ADezii | last post by:
If you are executing a code segment for a fixed number of iterations, always use a For...Next Loop instead of a Do...Loop, since it is significantly faster. Each pass through a Do...Loop that...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.