5,424,116 members and growing! (18,440 online)
Email Password   helpLost your password?
Web Development » ASP.NET » General     Intermediate

AJAX DataGrid(with client-side paging ) at glance

By Taha Amin

Genric AJAX library (fill textbox, dropdown, datagrid).
Javascript, XML, SQL, C#Windows, .NET, .NET 1.1, NT4, Win2K, WinXP, Win2003, ASP.NET, VS.NET2003, Visual Studio, DBA, Dev

Posted: 15 Aug 2005
Updated: 12 Mar 2006
Views: 103,218
Bookmarked: 40 times
Announcements
Want a new Job?



Search    
Advanced Search
Sitemap
13 votes for this Article.
Popularity: 2.47 Rating: 2.21 out of 5
7 votes, 53.8%
1
1 vote, 7.7%
2
0 votes, 0.0%
3
0 votes, 0.0%
4
5 votes, 38.5%
5
Note: This is an unedited contribution. If this article is inappropriate, needs attention or copies someone else's work without reference then please Report This Article

Sample Image - Ajax_DataGrid_at_glance.jpg

Abstract

 Hi there of course all of you hear about Ajax  ;) and about its performance,but the main problem is you have to write Javascript function for each case also I didn't found any code to fill Datagrid(note: Datagrid is converted to Html Table at Client-side) with Ajax so I decided to write  generic JavaScipt library for Ajax and also support Datagrid with paging.

How to run demo

you have to change database connection string in web.config also you have to change

javascript variable called:

var serverURL="http://163.121.16.41/">http://163.121.16.41/"

to you machine IP all of three files(AjaxLibHH09b.js,AjaxLibWS09b.js & HtmlTable2.aspx)

1]-I attach to projects you can use any of them

    a-GenricAjaxWS: it is HttpHandler webservice you call it like that

       http://localhost/GenricAjaxWS/GenricAjaxWS.asmx/GetData?sqlStr=select getdate()

       it returns XML DataSet.(of course 'select getdate()' is your sql select statement)

   or

   b-GenricAjaxHH: it is  you call it like that

    http://localhost/GenricAjaxWS/GenricAjaxWS.asmx/GetData?sqlStr=select%20getdate()

     but it works faster than Webservice(you must test it).

2]-to use GenricAjaxWS version use AjaxLibWS09b.js, to use  GenricAjaxHH version use AjaxLibhh09b.js

Details

The files(AjaxLibWS09b.js,AjaxLibHH09b.js) contains javascript function

called FillTable(mySelect,myDiv,myDataGridName,pageSize,sqlStr) it takes 5 parameters

1]-mySelect:dropdown list name(to filter datagrid).

2]-myDiv:html Div (to place grid on it).

3]-myDataGridName:datagrid name

4]-pageSize:count of rows in each datagrid page

5]-sqlStr:sql select statement.

there are another Function called FillTable(myDiv,myDataGridName,pageSize,sqlStr)

it works like the above but it doesn't take dropdown list name.

to use it you have to add this controls to you page

a]-add html hidden input called DataGrid1__PAGENUM.

b]-add html div and add id attribute to it(you will use this id).

c]-add any control to fire Fill function and add this line of code in page load

button1.Attributes.Add("onclick",
   "FillTable('oDiv','ClientPageDataGrid1',3, 
   'SELECT title,type,pub_id,price,advance FROM titles');");

while 'button1' is your control name

d]-add javascript file to project.

e]-add script tag in page head(in aspx) to map to script file.

and have fun.

Hints

there are some other functions

1]-FillTextBoxesFromDDLOnChange(mySelect,ar2,sqlStr):to fill a list of textboxes according to dropdown selection

DropDownList1.Attributes.Add("onchange",
   "FillTextBoxesFromDDLOnChange('DropDownList1',['TextBox1','TextBox2',
   'TextBox3','TextBox4','TextBox5'], 'SELECT title,type," + 
   "pub_id,price,advance FROM titles where title_id=');");

2]-FillDropDownFromDropDown(mySelect,mySelect2,sqlStr):to filter dropdown from another dropdown

DropDownList1.Attributes.Add("onchange", 
  "FillDropDownFromDropDown('DropDownList1','DropDownList2', 
   'SELECT fname,emp_id FROM employee WHERE pub_id=');");

3]-FillDDL(mySelect,sqlStr)&clearDDL(mySelect): to fill and clear dropdown.

 

Links

1-AJAX

2-Client-side paging for DataGrids

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Taha Amin


B/OSS.
Occupation: Team Leader
Company: http://www.linkdev.com/
Location: Egypt Egypt

Other popular ASP.NET articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 18 of 18 (Total in Forum: 18) (Refresh)FirstPrevNext
Subject  Author Date 
Generalcodemember1:46 21 Feb '07  
GeneralUsing vb.netmembernik_crash21:05 13 Sep '05  
GeneralSQL Injectionmemberbigals14:08 15 Aug '05  
GeneralRe: SQL InjectionmemberTaha Zayed23:09 15 Aug '05  
GeneralRe: SQL InjectionmemberMika0:51 17 Aug '05  
GeneralRe: SQL InjectionmemberJohn Goodwin7:29 17 Aug '05  
GeneralRe: SQL InjectionmemberTaha Zayed20:58 17 Aug '05  
GeneralRe: SQL InjectionmemberTaha Zayed21:06 17 Aug '05  
GeneralRe: SQL InjectionmemberTaha Zayed13:16 18 Aug '05  
GeneralRe: SQL InjectionmemberMark Brandon5:08 25 Aug '05  
GeneralRe: SQL InjectionmemberTaha Zayed5:33 25 Aug '05  
GeneralRe: SQL InjectionmemberMark Brandon6:12 25 Aug '05  
GeneralRe: SQL InjectionmemberTaha Zayed6:26 25 Aug '05  
GeneralRe: SQL InjectionmemberMark Brandon6:57 25 Aug '05  
GeneralRe: SQL Injection - encrypting javascriptmemberegozi138:01 14 Mar '06  
GeneralRe: SQL Injection - encrypting javascriptmemberTaha Zayed21:49 14 Mar '06  
GeneralThis is not encryption, but merely encodingmemberegozi137:03 15 Mar '06  
GeneralRe: This is encryption, but merely encodingmemberTaha Zayed8:22 15 Mar '06  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 12 Mar 2006
Editor:
Copyright 2005 by Taha Amin
Everything else Copyright © CodeProject, 1999-2008
Web18 | Advertise on the Code Project