I am a newbie on Infragistics 2008.1. Previously we used 2006.3 for .Net 1.1.
My dilemma is that I am trying to create a grid, design the columns (some hidden, and other kids of formatting) and bind it to data. For .Net 1.1 I used to simply create a dataset at design time and bound it after loading the dataset on page_load of the page. How will you do this now? For VS 2008, I now cannot drag a dataset on design mode to the page, and can only bind it to sqldatasource, objectdatasource et al. I tried the objectdatasource route, on select method I created and returned a dataset but this wipes out my previous formatting. Is there a quick HOW-TO for how to bind a webgrid to data for .Net 2.0 (and up) anywhere?
Thank you!
terealcantara said:
From my experience, when a datasource is assigned in code, it will wipe out some of the formatting done on design time. For instance, in design time, I have bound columns just LastName and FirstName on the grid. When I bound to a dataset in runtime with LastName, FirstName and YearsOfService, it displayed YearsOfService too, plus the heading captions are the dataset column names "LastName" and "FirstName" instead of "Last Name" and "First Name" which I assigned at design time.
I tried adding a dataset as a new item, dragged it to the the page where I have the grid from the App_Code and it becomes an XmlDataSource - which even renders on the page as a tree. Also, I cannot find the object when I try to look for it on design time (I was going to load it with data at design time).
As WombatEd mentioned previously, the AutoGenerateColumn property should be false. Further, the columns you set up at design time should be unbound. If you check the link I posted it should make things clearer.
As for the DataSet, the following link will give you a more specific step by step on setting this up:
http://help.infragistics.com/Help/NetAdvantage/NET/2008.2/CLR3.5/html/WebGrid_Binding_WebGrid_to_Northwind_Data_Set.html
The process is the same independent of the data table you decide to use.
terealcantara said: From my experience, when a datasource is assigned in code, it will wipe out some of the formatting done on design time. For instance, in design time, I have bound columns just LastName and FirstName on the grid. When I bound to a dataset in runtime with LastName, FirstName and YearsOfService, it displayed YearsOfService too, plus the heading captions are the dataset column names "LastName" and "FirstName" instead of "Last Name" and "First Name" which I assigned at design time.
Hunch: That kind of thing happens if you have Grid.AutoGenerateColumns=true. If you are defining attributes at design time, you need to set it false.
terealcantara said: I tried adding a dataset as a new item, dragged it to the the page where I have the grid from the App_Code and it becomes an XmlDataSource - which even renders on the page as a tree. Also, I cannot find the object when I try to look for it on design time (I was going to load it with data at design time).
If I understand Duc correctly, you may need to do this part in code:
declare your DataAdapter and DataSet in code, fill your data, and bind to WebGrid. An example of binding to a Customers table from northwind is as follows:
declare your DataAdapter and DataSet in code, fill your data, and bind to WebGrid.
An example of binding to a Customers table from northwind is as follows:
CustomersTableAdapter sqlDataAdapter1 = new CustomersTableAdapter();DataSet1 dataSet11 = new DataSet1();sqlDataAdapter1.Fill(dataSet11.Customers);this.UltraWebGrid1.DataSource = dataSet11.Customers;this.UltraWebGrid1.DataBind();
new
this
HTH
In VS 2008 you can add a DataSet to your project by right-clicking the project file in Solution Explorer and choosing Add New Item. Select DataSet in the Add New Item dialog box. You will be prompted to add the DataSet to your AppCode folder. Accept, the wizard to hook up your DataSet to data appears. It should be pretty self-explanatory from this point on to connect to your data. You have a named DataSet after you connected to a database after you are finish. The steps to bind to WebGrid are as follows: declare your DataAdapter and DataSet in code, fill your data, and bind to WebGrid.
The other issue here it seems is that you are trying to create a design time schema. For a tutorial on this, take a look at this article:
http://help.infragistics.com/Help/NetAdvantage/NET/2008.1/CLR2.0/html/WebGrid_Changing_the_Appearance_of_Bands.html
The basic concept includes adding columns that you want to show for the DataSet that you will bind to. These columns are unbound, and the BaseColumnName property is set to the column name in the DataTable. If the data is hierarchical, add additional bands and set the BaseTableName of each band. This process results in the grid showing only what you designed at design time for the data bound at runtime.