Take one function like
private void fillgrid()
{
here take sqlconnection
and using sqldataadapter or sqlcommand select query for filling in girdview
like
sqldataadapter sqlda=new sqldataadapter(sqlquery,con);
or
sqlcommand sqlcmd=new sqlcommand(sqlquery,con);
for sqldataadapter take dataset
as dataset ds=new dataset();
and fill sqldataadapter with dataset for getting data like
da.fill(ds);
and write
gridview1.datasource=ds; // gridview1 is id of gridview.
gridview1.databind();
}
you call this function in page_load...
like
if(!ispostback)
fillgrid();
use this one .....
gud luck
bye
}
pavan
|