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.
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
Using events etc. on controls inside controls etc. gets a little tricky and in general is a major pain in the ***, "if" i end up having to do this what i end up doing is just bubbling the events out...
Are you loading via load or do you have it on the actual page?
btw at what point are you trying to get/set those values? ie: page load, button click etc.
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!!
Are you saying you cannot access the grid from "within" the control or from the page that the control is on?