Welcome Guest Search | Active Topics | Sign In | Register

creating gridview at runtime Options
kskewes
Posted: Monday, March 9, 2009 11:59:34 AM
Rank: Newbie
Groups: Member

Joined: 3/9/2009
Posts: 2
I'm interested in using the EO Gridview control and would like to see some c# code that generates the control at run time. I need the typical template field and edit item template. Can I put all row in the gridview in edit mode? I would also like to allow for a popupmodal form for editing one row in a formview manner.

Thanks!
eo_support
Posted: Monday, March 9, 2009 12:11:24 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
Hi,

The easiest way is to put the Grid inside a user control, then load that user control with LoadControl method. You can set each individual Grid property by code, but since there are a lot of properties, it's much easier to set them at design time and then load them with one call. Please keep in mind that your code will have direct access to the user control, not the Grid in this case. If you wish to have direct access to the Grid, you will want to add a property in your user control code behind to expose the Grid so that whatever code that uses the user control will have access to the Grid.

If you do not wish to use user control, you can customize the Grid to whatever way you wanted at design time, then switch to HTML view to see what property has been set to what value. You would then duplicate the same in your code. For example, if you see BackColor="Red" in your HTML, you would do Grid1.BackColor=Color.Red in your code.

You can take a look of our dialog control for the popup modal feature.

Thanks!



kskewes
Posted: Tuesday, March 10, 2009 1:10:51 PM
Rank: Newbie
Groups: Member

Joined: 3/9/2009
Posts: 2
I'm not sure this answers my questions. I can not, due to system requirements, create the grid at design time. I must create the grid at run time. I allow the user to select what columns they want to view and in what order. So, I need to create the grid on the fly.
eo_support
Posted: Tuesday, March 10, 2009 1:27:23 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
Hi,

There are three primary tasks when you want to create the Grid dynamically:

1. Dynamically creates the Grid object and all columns. This part is very standard and easy, and this part does not have much particular with the Grid. For example, if you would like to dynamically creates a Grid inside a Panel control, you would do:

Code: C#
EO.Web.Grid grid = new EO.Web.Grid();
Panel1.Controls.Add(grid);


This is exactly the same as dynamically creating any other controls. You can also dynamically creating columns and it will be something like this:

Code: C#
EO.Web.StaticColumn column = new EO.Web.StaticColumn();
grid.Columns.Add(column);


There isn't much special about this except that you need to pay attention to the column type. The above code uses "StaticColumn". There are many column types and you will need to choose the type that fits your need.

One thing that you need to pay extra attention is that once you dynamically load a control, you need to make sure it is also loaded during postback. Otherwise server side events will not work. This is a general ASP.NET coding rule, not just for the Grid;

2. Set the Grid's appearance. The above code will create the Grid for you, but it won't have any appearance settings. So once you dynamically creates the grid, you will also need to set its apparance/style properties. Our previous post mentioned that the easiest way is for you to have it configured property at design time, then try to duplicate the settings with code;

3. Populate the Grid. Till now you have dynamically created the Grid and it looks good. However it does not have any data, so it's empty. The next step is to populate it with data. This step has nothing to do with whether the Grid is dynamically created or not. Both the documentation and samples covered this part extensively. So if you are not familiar with this part, please go over the the documentation and samples first. I would also suggest you to try this part on a Grid created at design time because regardless whether the Grid is created at design time or not, this step is exactly the same;

Hope this gives you a better picture. Please feel free to let us know if you still have any questions.

Thanks!


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.