GridView Control:
> Gridview will display multiple records in a tabular format.
> Gridview supports different types of customization like sorting,paging,inline editing
etc..
Syntax: Dataset ds=new DataSet();
da.fill(ds,"p");
Gridview1.Datasource= ds.tables["p"];
Gridview1.DataBind();
Note: DataSource will maintain address of memory component.
Databind will read records in a tabuler format.
Component Based Approach:
In real time Scenario, Component based approach will be based on for following reasons.
* Reputability
* Better Maintenance.
* Securing Database location from website Developer.
Creating A dll:-
*Goto New-> classlibrary project name: database lib
-e:\aspnet100
*goto class1.cs
..
using system.Data.Sqlclient;
using System.Data;
namespace datalib
{
public class mycomponent
{
public dataset getinfo(string sql)
{
sqlconnection con=new sqlconnection("userid=sa;password=;database=pubs");
SqlDataAdapter da=new SqlDataAdapter(sql,con);
dataset ds=dataset();
da.fill(ds,"demo");
return(ds);
}
}
}
build database lib then,This dll will be used by website developer to consume database logic.
Accessing DLL:
website menu.
|
Select add reference
|
browse[tab]
|
databaselib.dll
Gridview with sorting:-
Gridview supports implementation,this requires two steps
* allows sorting property to be true,this will provide column headings with hyperlinks.
* handling sorting event procedure,this will be executed towards column heading click.
Grid view with paging:-
paging is the concept of splitting bulk amount of data[info] into smaller blocks called pages,
only one page information will be downloaded at a time.this makes downloading fast.
this can be done in three steps.
1) allow paging property to true.
2) provide page size and navigation buttons.
3) handling page index change event procedure,it will be executed towards navigation button click.
properties:-
allow paging- true
page size- 5
position: Top Bottom
pagersettings:mode: nexpreviousfirstlast
firstpagetext: first;
lastpagetext: last;
previouspagetext: previous;
nextpagetext: next;
* events to be executed for paging
page index change of gridview-> Properties->eventschange
Grid view Fields:-
Customization fields
1) Bound Field:- it will display normal text based on dataset table column name,it is default field.
2) Template Field:- Used as a container for placing web server control into gridview.
(Need to insert manually in source view.)
3) Image Field:- it will place image with integration based on image name present in dataset table
columns.and webpage name[url] present in dataset table columns.
4) Hyperlink Field:- it will place hyperlink into grid view based on text and webpage name[url] present
in dataset table columns.
5) Command Field :- this provides special type of buttons,this will be binded to events of gridview.
select button- selected index changed event of gridview.
edit button- row editing event.
Placing the above fields:
gridview1 props,
|
remove auto generate fields checkbox selection.
select required field from available fields.
change properties according to requirement.
No comments:
Post a Comment