HOW TO FILL GRID VIEW WITH OUT USING SQLDATASOURCE AND
PROGRAMING?

Answer Posted / chandra kiran

i think we have to fill the gridview without using SQL datasource???

dataset ds=new dataset();
datatable dt =new datatable();
dt.tablename="SQL";
ds.tables.add(dt);
data column dc1=new datacolumn();
dc1.columnname="SNo";
dc1.datatype=Type.getType("System.Int32");
dt.columns.add(dc1);
//we are added 1 column to our datatable we can achieve this //1 in 1 statement in yhe following way
datacolumn dc2=dt.columns.add("Name",Type.GetType("System.String"));
//so now we have a table with 2 columns(SNo , Name)
//now we have add records to our table
datarow dr1=dt.newrow();
dr1[0]=1;
dr1[1]="kiran";
dt.rows.add(dr1);//we added 1 record
datarow dr2=dt.newrow();
dr2[0]=2;
dr2[1]="varma";
dt.rows.add(dr2);//in the same way we can add rows better //use arrays
//now we have a dataset and a datatable(SQL) inthat one and //this datatable contains two columns & 2 records now we //have to bind this 1 with our gridview
gridview.datasource=ds.tables[0] ;or
gridview.datasource=ds.tables["SQL"];or
gridview.datasource=dt;

output in gridview like
---------------------------------
SNo Name
---------------------------------
1 kiran
2 varma

Is This Answer Correct ?    5 Yes 3 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are the different execute methods of Ado.Net?

553


Explain the advantages and disadvantages of using datalist?

616


Explain the basic use of "dataview" and explain its methods.

533


How many major types of connection objects in ADO.NET?

595


What are the steps you will take to improve performance?

464






What is the role of clr?

531


What are the 3 major types of connection objects in ado.net?

543


What you mean by filtering of data?

542


What is the difference between Data adaptor and Data set?

515


What is data relation?

503


What is the procedure to call a Stored Procedure of Back End in ADO (ActiveX Data Object) and RDO (Remote Data Objects)?

560


What is the usage of the dataset object in ado.net?

489


What is sqlconnection and sqlcommand?

523


How to pass values into a datatable?

599


Which method is used by command class to execute SQL statements that return single value?

559