DATAtable basics..?

¿

¿ Mahesh Kumar

I have created a datatable as mydatatable and pointed that table to gridview...AM I CORRECT below..

---------------------------------

DataTable myDatatable=new DataTable("ParentTable");

DataColumn myDataColumn=new DataColumn();

DataRow myDataRow;


myDataColumn = new DataColumn();

myDataColumn.DataType = System.Type.GetType("System.Int32");

myDataColumn.ColumnName = "id";

myDataColumn.ReadOnly = true;

myDataColumn.Unique = true;

myDatatable.Columns.Add(myDataColumn);

for (int i = 0; i<= 2; i++)

{

myDataRow = myDatatable.NewRow();

myDataRow["id"] = i;

myDatatable.Rows.Add(myDataRow);

}


Myfirstgrid.DataSource = myDatatable; <------------------------------- pointing my data table to datagrid

---------------------------------------------
 
E

Elton Wang

Yes. However, in order to show the web datagrid, add one more code:

Myfirstgrid.DataBind();

HTH

I have created a datatable as mydatatable and pointed that table to gridview...AM I CORRECT below..

---------------------------------

DataTable myDatatable=new DataTable("ParentTable");

DataColumn myDataColumn=new DataColumn();

DataRow myDataRow;


myDataColumn = new DataColumn();

myDataColumn.DataType = System.Type.GetType("System.Int32");

myDataColumn.ColumnName = "id";

myDataColumn.ReadOnly = true;

myDataColumn.Unique = true;

myDatatable.Columns.Add(myDataColumn);

for (int i = 0; i<= 2; i++)

{

myDataRow = myDatatable.NewRow();

myDataRow["id"] = i;

myDatatable.Rows.Add(myDataRow);

}


Myfirstgrid.DataSource = myDatatable; <------------------------------- pointing my data table to datagrid

---------------------------------------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top