Hi, I'm having trouble using properties and events when I put a WebGrid in a user control. I followed these instructions:
In some applications, there may be a situation where the
WebGrid displays data and multi-level data from your database on a Web Form. It also allows you to modify the data and update your database with the changes.
Toolbox Item: UltraWebGrid
Namespace: Infragistics.WebUI.UltraWebGrid
This project places a WebGrid on a User Control and this user control is placed on a Web Form. This methodology could be used to provide a list of items in a shopping cart as the user makes shopping cart item selections.
But I don't have access to the AutoGenerateColumns or the width and height properties. I also can't use the InitilizeLayout event. What am I missing? could you please help me out... with Visual Basic code would be greatly appreciated.
vs2005, Visual Basic, NetAdvantage 8.1.20081.1000
Thank you for your time.
Are you saying you cannot access the grid from "within" the control or from the page that the control is on?
Hi Chris, Thanks for responding. Sorry for the confusion. When I use a WebGrid normally (not in a user or custom control) I can use the grid without problems. I can access properties and events and everything is fine.
When I put my user grid (ascx) onto a web form (default.aspx), I can't access any properties or events for the user grid (ascx), unless the code is in the ascx file itself. But I don't want that. The grid columns will be different depending what button the user clicked. I would like to have all the code for using my user grid in default.aspx but It won't execute any events and I can't set any properties. I placed a breakpoint inside the InitializeLayout event but it dosen't even fire.
UPDATE: Ok I've tried to expose some simple properties, like width and height but the code is still being ignored. This is inside the ascx code-behind file.
Code Example:
Public Property Width() as Unit
Get
return WebGrid.Width
End Get
Set(ByVal value As System.Web.UI.WebControls.Unit)
WebGrid.Width = value
End Set
End Property
Also, how does one expose deeper properties such as DisplayLayout.AutoGenerateColumns or Layout.Bands(0).Columns.FromKey("").Hidden?
Also, how would I expose events for my grid?
I hope I have been clear enough.
Thanks for your help Chris!!
Just curious...if your going to put all of the grid related code in the main ASPX page what is our goal in placing the grid in a user control? Not sure I see the benefit, but maybe I missed that in the original message?
That said, this is basically a function of the way OO programming works. The grid is created as a proptected member of the user control, which is itself a member of the main ASPX page. You could expose a property on the user control that exposes the grid control contained in it. That would give you programatic access to all of the controls properties and events at runtime:
Then you could simply say in your ASPX page:
this.MyUserControl.Grid.somegridproperty = foo;
Devin
Sorry, just saw it attached to the top of your post.
Can I get a copy of this sample?
Hi Devin,
Thanks for the reply. I'll try your sample.
Thanks again.
I will refer you to my previous suggstion of simply exposing the entire grid control as a property in the ASCX. Doing that,you could in your main ASPX page then simply say (C#, sorry..my VB is pretty rusty):
this.MyUserControl.Grid.InitializeDataSource += new InitializeDataSourceHandler(somemethod);
Since in my example, the "Grid" property exposed by the user control is simply returns the UltraWebGrid, you have access to the entire UltraWebGrid object model from the ASPX page. Otherwise your going to have to put a facade over every property, method and event that you want to expose from the Grid through the User Control, which would be a lot of work.
I have attached a sample WebSite that demonstrates what I am talking about.
Hello Chris and Devon. Thank you for your response. I've tried another approach to this, but i'm still having issues. Here's what i've done:
I still have an Infragistics webgrid in an ascx file. That's all that's on it. I don't have a datasource control, because all that gets done in code. I've exposed an event on the ascx page that looks like this:
Public Event InitializeLayout As Infragistics.WebUI.UltraWebGrid.InitializeLayoutEventHandler
With the above line of code, I should be able to use and catch this event when using the usercontrol on a regular aspx page, correct? However, the InitializeLayout event doesn't fire - even when I put a breakpoint in it. Is my code wrong? I don't understand why this doesn't work. Help apreciated.
Thank you.