Wednesday, November 3, 2010

Make asp.net database driven applications in opensource style

What about making asp.net application just in the same way you work with your favourite scripting language like php ? How can I bind dataset without
using heavy Grid View from server side? How can I achieve paging and sorting in client-side? How to make super fast web applications with asp.net ?
OK. Here is the answer ..

As experienced programmer in both php and asp.net what I have realize is , php is flexible in front end developments and it is kind of ahead
performance wise . The main overhead asp.net developers face is heavy server controlls.

In fact there is no difference in asp.net server controlls and html controlls if we deeply have a look , keep in mind that grid view render as Html
Table control, and this is the trick! If your are good in programming , dynamically creating html table in serverside is not a big deal .Just cares
for some syntaxes.

Now here we are going to bind same dataset in two differentways to measure performance .

well We did it! Let us start coding.

First step :
we will bind with generic gridview controll .

Please note that configure some of your database table and field names in bellow code sample.

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false">

</asp:GridView>


Codebehind


protected void Page_Load(object sender, EventArgs e)

{

String Q;
Sql command cmd;
Sql DataReader dr;


SqlConnection conn = new SqlConnection(); 

conn.ConnectionString = ConfigurationManager.ConnectionStrings        ["cn"].ConnectionString.ToString(); 

conn.Open(); 

Q = "select * from ATEST ";

cmd= New Sqlcommand(Q, conn);  

dr = cmd.ExecuteReader();          

Gridview1.DataSource = dr;

Gridview1.DataBind();

}


Second step :
we will bind with creating dynamic html table .

protected void Page_Load(object sender, EventArgs e)

{


String Q;

SqlCommand cmd;

SqlDataReader dr;



SqlConnection conn = new SqlConnection();


conn.ConnectionString = ConfigurationManager.ConnectionStrings["cn"].ConnectionString.ToString();


conn.Open();


Q = "select * from ATEST";


cmd= new SqlCommand(Q, conn);



Response.Write("<table id='example'>");

Response.Write("<tbody>");

Response.Write("<thead><tr><th>Rendering engine</th><th>Browser</th></tr></thead>");


int i = 0;

while (dr.Read())

{


string id = dr.GetInt32(dr.GetOrdinal("CompanyID")).ToString();


string did = dr.GetString(dr.GetOrdinal("DeveloperCode"));





Response.Write(" <tr>");


Response.Write(" <td>" + id + "</td><td><a rel='facebox' href='Editgrid.aspx'> "+ did + "</a></td>");



Response.Write(" </tr>");




i++;


}



Response.Write("</tbody>");




Response.Write("</table>");







}

You can make your table just as gridview by applying appropriate styles . Notice here I applied popular jquery “facebox “ popup in table . You can
use it to update data in row by row .


If your good in front end development and love playing with clientside scripting it is all yours . Visit jquery datatable website . http://www.datatables.net/

Apply datatable properties to achieve paging and sorting in high efficent way in clentside .



Trace record taken by gridview sample.Notice the final figure.



Trace record taken by Table sample.Notice the final figure.




So buddy Asp.net developers dnt worry bout heavy servercontrolls anymore . Cheers …!