I am a PHP developer but now I am learning asp.net with C# as it is a requirement of our company. I am familiar with the basics of C# and oops. The problem I am facing is that I learned how to retrieve values from the database and make a data table. Now from this I know that I can bind a grid control to display the data but this technique restricts me to do some of my own stuff to the datagrid. Now what I want is that I used to hard code the table in PHP if I needed to build a table
like:
<?php
*/
retrive the data from the database and store it in an array using $row_sql = mysql_fetch_array() function
/*
....
....
?>
<table>
<tr>
<td><?php $row_sql['fieldname']; ?></td>
</tr>
....
....
</table>
?>
I know that I can do such a thing with a repeater but not sure that I want to use such a control or its just because that i am not so familiar with asp.net style.
So can anyone please guide me how can I do this?
Or please tell me what should I do to learn asp.net if I know how to do it in PHP?
Update:
Ok here is what I did but I am still getting an error.
Firstly I created a database by filling the dataset from dataadapter, then I used the code as suggested but I am getting the following error:
foreach statement cannot operate on variables of type ‘System.Data.DataTable’ because ‘System.Data.DataTable’ does not contain a public definition for ‘GetEnumerator’
You’re not limited to using only the Grid controls at your disposal – you can generate your own markup by looping through the data rows in the specific data table. You can for instance do something like this:
That will loop through each data row in the data table and write out the contents of columns 1-3 (assuming their names are “Column1”, “Column2” and “Column3”, of course), each in their own TD, wrapped in a TR. But I’m sure you figured that out already…
My suggestion would be to rather implement an MVC framework (whether it be the ASP.NET MVC framework or your own), as it would be easier to adapt, coming from a PHP background.
EDIT I updated the code snippet to use the DataView type for enumeration… Just remember to include the System.Data namespace to use the “AsDataView()” extension method. Alternatively, you could get a DataView as follows: