public
IQueryable<Product> GetProducts()
{
var products = from p in db.Product.Include("ProductDetail")
select p;
return products;
}
public IQueryable<ProductDetail> FindProductDetailsByProduct(Guid productID)
{
var productDetails = from pd in db.ProductDetail.Include("Product")
select pd;
return productDetails.Where(p=> p.Product.ProductID == productID);
}
In my codebehind I copied the DefineGridStructure function from the example given in the Grid / Creating Hierarchy Programmatically example: http://demos.telerik.com/aspnet-ajax/grid/examples/programming/hierarchy/defaultcs.aspx In this example, it uses a SQLDataSource whereas I'm wanting to bind the data programmatically. I tried setting the datasource using my GetProducts() function and convert to list and assign to grid. I have two columns ProductID and ProductName in my Masterview and two columns in my Detailview. The grid loads and is populate however, when I try to expand, it does not find the relation key (ProductID) of the Masterview. ProductID is the primary key in my Product table and it is the foreign key in my ProductDetail table.
I am new to using RadGrid and I am not seeing what I am doing wrong. See actual code below and please point me in the right direction. If there is an example that uses both programmatic creation a gird hierarchy and advanced binding I would appreciate if you could forward me the link. All the samples I have reviewed use on one aspect and I am having trouble putting it all together, including the inserts, updates and deletes. My business rules are too complex to simply use an entity datasource control.
private void DefineGridStructure()
{
RadGrid RadGridProducts = new RadGrid();
RadGridProducts.ID =
"RadGridProducts";
RadGridProducts.DataSource = GetProductDataSource();
RadGridProducts.MasterTableView.DataKeyNames =
new string[] { "ProductID" };
RadGridProducts.MasterTableView.Name =
"ProductsView";
RadGridProducts.MasterTableView.CommandItemDisplay =
GridCommandItemDisplay.Top;
RadGridProducts.Width =
Unit.Percentage(98);
RadGridProducts.PageSize = 20;
RadGridProducts.AllowPaging =
true;
RadGridProducts.AllowSorting =
true;
RadGridProducts.PagerStyle.Mode =
GridPagerMode.NextPrevAndNumeric;
RadGridProducts.AutoGenerateColumns =
false;
RadGridProducts.ShowStatusBar =
true;
RadGridProducts.AllowAutomaticDeletes =
true;
RadGridProducts.AllowAutomaticInserts =
true;
RadGridProducts.AllowAutomaticUpdates =
true;
RadGridProducts.ClientSettings.ClientEvents.OnRowDblClick =
"RowDblClick";
//Register all events for grid
RadGridProducts.ItemDeleted +=
new GridDeletedEventHandler(RadGridProducts_ItemDeleted);
RadGridProducts.ItemInserted +=
new GridInsertedEventHandler(RadGridProducts_ItemInserted);
RadGridProducts.ItemUpdated +=
new GridUpdatedEventHandler(RadGridProducts_ItemUpdated);
RadGridProducts.InsertCommand +=
new GridCommandEventHandler(RadGridProducts_InsertCommand);
RadGridProducts.ItemCommand +=
new GridCommandEventHandler(RadGridProducts_ItemCommand);
RadGridProducts.PreRender +=
new EventHandler(RadGridProducts_PreRender);
RadGridProducts.NeedDataSource +=
new GridNeedDataSourceEventHandler(RadGridProducts_NeedDataSource);
RadGridProducts.DetailTableDataBind +=
new GridDetailTableDataBindEventHandler(RadGridProducts_DetailTableDataBind);
RadGridProducts.MasterTableView.PageSize =20;
RadGridProducts.MasterTableView.EditFormSettings.UserControlName =
"~/Controls/Products/ProductDetailsControl.ascx";
RadGridProducts.MasterTableView.EditFormSettings.EditFormType =
GridEditFormType.WebUserControl;
RadGridProducts.MasterTableView.EditFormSettings.EditColumn.UniqueName =
"EditCommandColumn1";
//Add columns
GridEditCommandColumn editColumn;
editColumn =
new GridEditCommandColumn();
editColumn.ButtonType =
GridButtonColumnType.LinkButton;
RadGridProducts.MasterTableView.Columns.Add(editColumn);
GridBoundColumn boundColumn;
boundColumn =
new GridBoundColumn();
boundColumn.DataField =
"ProductID";
boundColumn.HeaderText =
"Product ID";
boundColumn.UniqueName =
"ProductID";
boundColumn.Visible =
true;
RadGridProducts.MasterTableView.Columns.Add(boundColumn);
boundColumn =
new GridBoundColumn();
boundColumn.DataField =
"ProductName";
boundColumn.HeaderText =
"Product";
RadGridProducts.MasterTableView.Columns.Add(boundColumn);
boundColumn =
new GridBoundColumn();
boundColumn.DataField =
"ProductModel";
boundColumn.HeaderText =
"Model";
RadGridProducts.MasterTableView.Columns.Add(boundColumn);
boundColumn =
new GridBoundColumn();
boundColumn.DataField =
"Weight";
boundColumn.HeaderText =
"Weight";
RadGridProducts.MasterTableView.Columns.Add(boundColumn);
boundColumn =
new GridBoundColumn();
boundColumn.DataField =
"Dimensions";
boundColumn.HeaderText =
"Dimensions";
RadGridProducts.MasterTableView.Columns.Add(boundColumn);
boundColumn =
new GridBoundColumn();
boundColumn.DataField =
"SKU";
boundColumn.HeaderText =
"SKU";
RadGridProducts.MasterTableView.Columns.Add(boundColumn);
GridButtonColumn deleteColumn;
deleteColumn =
new GridButtonColumn();
deleteColumn.ButtonType =
GridButtonColumnType.LinkButton;
deleteColumn.CommandName =
"Delete";
deleteColumn.Text =
"Delete";
deleteColumn.ConfirmText =
"Are you sure you wish to Delete this item?";
RadGridProducts.MasterTableView.Columns.Add(deleteColumn);
//Detail table - (II in hierarchy level)
GridTableView tableViewProductDetails = new GridTableView(RadGridProducts);
tableViewProductDetails.DataSource = GetProductDetailsDataSource();
tableViewProductDetails.DataBind();
tableViewProductDetails.Name =
"ProductDetailsView";
tableViewProductDetails.Width =
Unit.Percentage(100);
tableViewProductDetails.DataKeyNames =
new string[] { "ProductDetailID" };
GridRelationFields relationFields = new GridRelationFields();
relationFields.MasterKeyField =
"ProductID";
relationFields.DetailKeyField =
"ProductID"; /*This line throwing error*/
tableViewProductDetails.ParentTableRelation.Add(relationFields);
RadGridProducts.MasterTableView.DetailTables.Add(tableViewProductDetails);
//Add columns
boundColumn =
new GridBoundColumn();
boundColumn.DataField =
"ProductDetailID";
boundColumn.HeaderText =
"ProductDetailID";
boundColumn.UniqueName =
"ProductDetailID";
tableViewProductDetails.Columns.Add(boundColumn);
boundColumn =
new GridBoundColumn();
boundColumn.DataField =
"MSRP";
boundColumn.HeaderText =
"MSRP";
tableViewProductDetails.Columns.Add(boundColumn);
//Add the RadGrid instance to the controls
this.PlaceHolder1.Controls.Add(RadGridProducts);
}
Regards,
Fred
Webpage error details
User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET CLR 3.0.30618; InfoPath.2; SLCC1)
Timestamp: Wed, 23 Dec 2009 16:34:21 UTC
Message: Object expected
Line: 87
Char: 4
Code: 0
URI: https://www.TestSite.com/controls/RadControls/Editor/Dialog.aspx?dialog=ImageManager&editorID=dnn_ctr474_EditHTML_teContent_teContent&useSession=0&sessionID2=ABCSessionID&language=en_US&UseEmbeddedScripts=yes&tabid=86
Is this an issue you've seen? Any help would be so greatly appreciated as we use the RadControls extensively and absolutely love them.
Regards,
Marco Andrade

Then, when I have less than 20 rows, no paging controls are displayed, that's fine.
But if I have 25 records it shows me the text box, where customer can specify desired page size. Ok.
If he specify here 30, nothing will change, page size will remain 20. Yes. if he sets page size to 25, all the records will be displayed and paging control disappears. I belive that should happed by default if he specify page size more than records in the grid.
Why it keeps the current page size instead of taking the max number of records as new value?
Am I missing some scenarios where it could be misleading?
Thank you,
Alex.
| Imports System.Data |
| Partial Class MyRadGrid |
| Inherits System.Web.UI.Page |
| Protected Sub RadGrid1_NeedDataSource(ByVal source As Object, ByVal e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles RadGrid1.NeedDataSource |
| Dim strSQL As String |
| strSQL = "SELECT SupplierID, ContactName, City, Region, PostalCode, Country FROM Suppliers" |
| Dim strCacheName As String = "SupplierData" |
| Dim ds As DataSet = CType(Cache(strCacheName), DataSet) |
| If ds Is Nothing Then |
| Dim aDB As New AccessDataSource("~/App_Data/Northwind.mdb", strSQL) |
| Dim mydv As System.Data.DataView = CType(aDB.Select(DataSourceSelectArguments.Empty), System.Data.DataView) |
| Dim dt As DataTable = mydv.ToTable |
| ds = New DataSet |
| ds.Tables.Add(dt) |
| Cache.Insert(strCacheName, ds, Nothing, Cache.NoAbsoluteExpiration, New System.TimeSpan(0, 0, 20)) |
| End If |
| RadGrid1.DataSource = ds |
| End Sub |
| End Class |
I've placed a grid into a RadWindow. It looks great and I love the functionality. However, If I do a filter and the resulting data is small (say only 2 rows) then when I click on the filter again, the filter options are cut off inside the window. It prevents me from turning the filter off or looking at other options, forcing me to close the window. I assume there's a way around this?