pull data from database and got few data inside the database,
i wan it to show automatically on the page by looping.
how to code it?
Since you've fetched all the data contents from DataTable from a db,no need for you to looping and show the data,plz just use a GridView+SqlDataSource,accroding to the wizard window you'll be easy to finish that task!
Using SqlDataSource control+GridView you can do CRUD!!!!
Seem you are not familar with ASP.NET Data Access, so firstly I suggest you to do some research on ASP.NET Data Bound control. The document below elabrate what kind of data bound controls asp.net has:
TheDataListcontrol
renders data as table and enables you to display data records in different layouts, such as ordering them in columns or rows. You can configure theDataListcontrol
to enable users to edit or delete a record in the table. (TheDataListcontrol
does not take advantage of the capabilities of data source controls for modifying data; you must supply this code yourself.) TheDataListcontrol
differs from theRepeatercontrol
in that theDataListcontrol
explicitly places items in an HTML table, where as theRepeatercontrol
does not.
TheListViewcontrol
displays data from a data source in a format that you define using templates. The template contains the formatting, controls, and binding expressions that are used to lay out the data. TheListViewcontrol
is useful for data in any repeating structure, similar to theDataListandRepeatercontrols.
However, unlike theDataListandRepeatercontrols,
theListViewcontrol implicitly supports edit, insert, and delete
operations, as well as sorting and paging functionality.
</div> </div>
Please mark the replies as answers if they help or unmark if not.
Feedback to us
ctee
Member
115 Points
250 Posts
Looping data.
May 21, 2012 03:48 AM|LINK
Hi,
I need help for the code.
I pull data from database and got few data inside the database,
i wan it to show automatically on the page by looping.
how to code it?
Thanks.
tusharrs
Contributor
3230 Points
668 Posts
Re: Looping data.
May 21, 2012 04:32 AM|LINK
http://www.dotnetperls.com/datatable-foreach
http://www.dotnetperls.com/datatable
http://forums.asp.net/t/1059398.aspx/1
http://www.dotnetfunda.com/articles/article12.aspx
( Mark as Answer if it helps you out )
View my Blog
TimoYang
Contributor
3732 Points
1275 Posts
Re: Looping data.
May 21, 2012 05:06 AM|LINK
Since you've fetched all the data contents from DataTable from a db,no need for you to looping and show the data,plz just use a GridView+SqlDataSource,accroding to the wizard window you'll be easy to finish that task!
Using SqlDataSource control+GridView you can do CRUD!!!!
http://www.asp.net/web-forms/tutorials/data-access/accessing-the-database-directly-from-an-aspnet-page/inserting-updating-and-deleting-data-with-the-sqldatasource-cs
santosh.jagd...
Star
7625 Points
1454 Posts
Re: Looping data.
May 21, 2012 05:12 AM|LINK
hi ctee,
you can use for each loop. But where you want to display data?
in some control you don't need to loop through all records, you simply bind the datasource to that control and it will take care of all the records.
MCP
ctee
Member
115 Points
250 Posts
Re: Looping data.
May 21, 2012 06:42 AM|LINK
Hi,
Below are the sample output that i try to do:
Name:AAA
Start Time: 2012-05-12 08:00:00 (Stop)*note that, this stop actually is "stop logo"
End Time : 2012-05-13 09:00:00
_________________________________________________________________________
Name :BBB
Start Time : 2012:05:10 09:00:00 (Start)*note that, this stop actually is "start logo"
End Time :
TimoYang
Contributor
3732 Points
1275 Posts
Re: Looping data.
May 21, 2012 06:48 AM|LINK
Hi ctee——
Use DataList and do to change the ItemTemplate to a table with these bound fields……
Mamba Dai - ...
All-Star
23531 Points
2683 Posts
Microsoft
Re: Looping data.
May 24, 2012 06:10 AM|LINK
Hi,
Seem you are not familar with ASP.NET Data Access, so firstly I suggest you to do some research on ASP.NET Data Bound control. The document below elabrate what kind of data bound controls asp.net has:
http://msdn.microsoft.com/en-us/library/ms228214.aspx
And this is a tutorial about asp.net data control, you can follow it to study data bound controls:
http://www.asp.net/web-forms/overview/aspnet-data-controls
For your practice scenario, as the reply above mentioned, the DataList or ListView are your consideration:
DataList
Control
<div style="text-align: left; widows: 2; text-transform: none; text-indent: 0px; letter-spacing: normal; font: 13px 'Segoe UI', Verdana, Arial; white-space: normal; orphans: 2; color: #000000; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;" xmlns=""> <div style="padding-left: 15px; display: block; clear: both;" class="sectionblock">The DataList control renders data as table and enables you to display data records in different layouts, such as ordering them in columns or rows. You can configure the DataList control to enable users to edit or delete a record in the table. (The DataList control does not take advantage of the capabilities of data source controls for modifying data; you must supply this code yourself.) The DataList control differs from the Repeater control in that the DataList control explicitly places items in an HTML table, where as the Repeater control does not.
For more information, see DataList Web Server Control Overview.
</div> </div> <div style="text-align: left; widows: 2; text-transform: none; text-indent: 0px; letter-spacing: normal; font: 13px 'Segoe UI', Verdana, Arial; white-space: normal; orphans: 2; color: #000000; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;" xmlns=""> <div style="margin-top: 9px; margin-bottom: 19px;" class="LW_CollapsibleArea_TitleDiv"> <div></div> </div> </div> <div style="padding-left: 15px; display: block; clear: both;" class="sectionblock">
The ListView control displays data from a data source in a format that you define using templates. The template contains the formatting, controls, and binding expressions that are used to lay out the data. The ListView control is useful for data in any repeating structure, similar to the DataList and Repeater controls. However, unlike the DataList and Repeater controls, theListView control implicitly supports edit, insert, and delete operations, as well as sorting and paging functionality.
</div> </div>Feedback to us
Develop and promote your apps in Windows Store