datatable and gridview...binding..? doubt?

  • Thread starter =?iso-8859-1?Q?=BF_Mahesh_Kumar?=
  • Start date
?

=?iso-8859-1?Q?=BF_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

---------------------------------------------
 
S

Scott Allen

Hi Mahesh:

The code you have here will set the DataSource to reference the
DataTable you've created. Remember to call DataBind to bind the data.

Note you have "myDataColumn=new DataColumn()" in your setup code
twice, you'll only need it once.
 
¿

¿ Mahesh Kumar

Yes right..Thanks scott :)



Scott Allen said:
Hi Mahesh:

The code you have here will set the DataSource to reference the
DataTable you've created. Remember to call DataBind to bind the data.

Note you have "myDataColumn=new DataColumn()" in your setup code
twice, you'll only need it once.

--
Scott
http://www.OdeToCode.com/blogs/scott/

-

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