473,396 Members | 1,967 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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

-

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

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

Nov 19 '05 #1
2 1079
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/

On Thu, 13 Oct 2005 20:34:43 +0530, ¿ Mahesh Kumar
<cy**********@gmail.com> wrote:
-

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

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


Nov 19 '05 #2
Yes right..Thanks scott :)

"Scott Allen" <sc***@nospam.odetocode.com> wrote in message
news:kc********************************@4ax.com...
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/

On Thu, 13 Oct 2005 20:34:43 +0530, ¿ Mahesh Kumar
<cy**********@gmail.com> wrote:
-

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
---------------------------------------------

Nov 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: s.gregory | last post by:
My page layout is like this: Page >DataList (databound using ObjectDataSource1 contained in page) >>Items >>>UserControl >>>>GridView (databound using another ObjectDataSource2 contained in...
0
by: witek | last post by:
I am lost. There is a dataTable with data which I want to dispaly in GridView. dataTable is not connected to any database. Just dataTable with data. There is a class wich is used as column...
4
by: Tomasz Jastrzebski | last post by:
Hello Everyone, I have a GridView control bound to a plain DataTable object. AutoGenerateEditButton is set to true, Edit button gets displayed, and RowEditing event fires as expected.
9
by: Anil Gupte | last post by:
After reading a tutorial and fiddling, I finally got this to work. I can now put two tables created with a DataTable class into a DataRelation. Phew! And it works! Dim tblSliceInfo As New...
9
by: =?Utf-8?B?RGljaw==?= | last post by:
I have a function that creates a DataSet, populates its many DataTables and then returns the DataSet. I want to bind separate controls to each of the DataSet's DataTables, e.g. a separate...
15
by: Joseph Geretz | last post by:
I'm a bit puzzled by the current recommendation not to send Datasets or Datatables between application tiers. http://support.microsoft.com/kb/306134 ...
7
by: =?Utf-8?B?QWxla3MgS2xleW4=?= | last post by:
I use in my asp.net code dataset and populate datatable using dataadapter. The problem is that my code demand huge amount of memory and I am looking for way reduce this demand. At this time I...
2
by: DC | last post by:
Hi, I am using a GridView to present data in a DataTable, which I store only in ViewState and when the user hits the "OK" button the rows in the DataTable will be used to execute transactions. ...
1
fayazmd
by: fayazmd | last post by:
Hi, I have worked in various projects. In some projects GridView binding is done by DataTable and in other by IList(List<ClassName>). Most client projects they have followed this IList<> and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.