Thanks
protected void outdatedChanged(object sender, EventArgs e) |
{ |
CheckBox cb = (CheckBox)sender; |
if (cb.Checked) |
{ |
providersGrid.DataSourceID = "CCprovidersIncludingOutdated"; // master grid |
//I want to set the detail grids datasources here for outdated content |
} |
else |
{ |
providersGrid.DataSourceID = "CCproviders"; // master grid |
//I want to set the detail grids datasources here |
} |
} |
16 Answers, 1 is accepted
You can access the DetailTables and set its datasource as shown below:
protected void outdatedChanged(object sender, EventArgs e) |
{ |
CheckBox cb = (CheckBox)sender; |
if (cb.Checked) |
{ |
providersGrid.DataSourceID = "CCprovidersIncludingOutdated"; // master grid |
foreach (GridDataItem dataItem in providersGrid.MasterTableView.Items) |
{ |
if (dataItem.Expanded) |
{ |
GridTableView nestedTableView = (GridTableView)dataItem.ChildItem.NestedTableViews[0]; |
nestedTableView.DataSourceID = ""; //set datasource here; |
//similarly you can repeat the same for the 3rd level detailtable |
} |
} |
} |
} |
Also refer to the following help document which explains on how to access detail tables:
Traversing detail tables/items in Telerik RadGrid
Thanks
Princy.
So tried doing it from the link you recommended and I can set the datasource this way for the second level hierarchy:
providersGrid.DataSourceID = "CCprovidersIncludingOutdated";
GridTableView nestedTableViewService = (providersGrid.MasterTableView.Items[0] as GridDataItem).ChildItem.NestedTableViews[0];
nestedTableViewService.DataSourceID = "CCservicesIncludingOutdated";
But I am having trouble setting the third level. It gives me an out of bounds error if I try this:
GridTableView nestedTableViewFeed = nestedTableViewService.Items[0].ChildItem.NestedTableViews[0];
Any suggestions?
Thanks
When a level is not expanded and you are using a standard loading mode, its nested items will not be accessible. Hence the exception.
To work-around this, you can use client load mode for the control - all the info for the detail tables will be pre-fetched.
I hope this helps.
Sincerely yours,
Yavor
the Telerik team
Check out Telerik Trainer , the state of the art learning tool for Telerik products.
THanks
There are basically two modes of hierarchy loading - server and client. With server loading, only the top-level of the control is fetched initially. All other inner levels are fetched as they are expanded. With client load mode, all levels are pre-fetched, and no subsequent posts to the server are made, as the levels are expanded. One possible option in this case would be to enable client side loading for the hierarchy, but also allow paging. This will balance the setup.
Sincerely yours,
Yavor
the Telerik team
Check out Telerik Trainer , the state of the art learning tool for Telerik products.
Can you please elaborate on the required setup? How do you need to change the source for the detail table? How/where do you need to change the page index? Any additional information will help me better address the question at hand.
Kind regards,
Yavor
the Telerik team
Check out Telerik Trainer , the state of the art learning tool for Telerik products.
I have a 3 level hierarchical grid. The 3 tables are providers, services, feeds. A provider can have 1 or more services and a service can have one or more feeds. There are multiple pages of providers, and there may be multiple pages in the expanded state of services and feeds if there are more than 10.
Each of the tables has a field called end_date.It starts out at null. If the user deletes a provider, service or feed I set the end_date to now so that we keep a record of when that particular record was terminated.
When I create my original dataset for the grid for all 3 tables, my query has a "where end_date is null or end_date > getdate()" so that I retrieve all records where the end_date is not less than right now. I have a checkbox that the user can check if he wants to see all data including outdated data (which would include records where end_date<getdate() ). So in my code behind, I wanted to have an oncheckbox changed event handler, which if it is checked, change all 3 table datasourceIDs to the query retrieving all records and not only those with valid dates. And then if it is not checked, changed it back in the codebehind (or client side if necessary) to only select those records the have an end_date either of null or > now. That is the first problem I am having of trying to set not only the providers (which works fine) datasourceID, but the services and feeds datatsourceID as well even if the grid is not expanded.
Second problems is with the paging of detail tables. I have implemented the library submission for keeping a hierarchical grid expanded on a rebind. I practially took the code as is, dropped it in my code, and except for changing a few variable names, it works on the surface exceprt for a few glitches which I don't know how or where to fix.
The feeds table is my lowest level detail grid. I may have many pages of feeds under a service. Most of the editing is being done at the feeds level. I created rad popup custom windows to do the editing of feeds. If I am on the 3rd page of feeds under a particualr service and edit a feed there, a window pops up to do the editing, When the user clicks ok on that page, that page's code saves the feed, and returns to the grid, and the grid rebinds. I want to stay on the current feed page to most likely edit the next feed, but it returns to the first page(in the detail table) of feeds.You suggested setting the currentpageindex for the master and detail tables, but I do not know which function that should be set in, and I dont know the proper syntax of how to use it.
I hope I made myself clear enough for you to understand my questions, and hope this is enough information for you to help me.
Thank you,
Laura
Hi Laura,
Thank you for the additional details supplied, which make the setup clear.
Basically, altering the datasources for the controls is not recommended in this scenario. You can, however, take a more stable and straightforward approach.
One possible option is to directly alter the select statement(s) for the present datasources, and rebind the grid. For example, let us take the following setup, demonstrated in this sample:
http://demos.telerik.com/aspnet-ajax/grid/examples/hierarchy/declarativerelations/defaultcs.aspx
It is a three level hierarchy. For each level of the hierarchy, a different datasource control is used, like so:
<asp:SqlDataSource ID="SqlDataSource1" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
ProviderName="System.Data.SqlClient" SelectCommand="SELECT * FROM Customers"
runat="server"></asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource2" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
ProviderName="System.Data.SqlClient" SelectCommand="SELECT * FROM Orders Where CustomerID = @CustomerID"
runat="server">
<SelectParameters>
<asp:SessionParameter Name="CustomerID" SessionField="CustomerID" Type="string" />
</SelectParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource3" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
ProviderName="System.Data.SqlClient" SelectCommand="SELECT * FROM [Order Details] where OrderID = @OrderID"
runat="server">
<SelectParameters>
<asp:SessionParameter Name="OrderID" SessionField="OrderID" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
The first select statement is:
SelectCommand="SELECT * FROM Customers"
This selects all fields and records from the Customers table. Now, let us assume that you wanted to display only Records, which CustomerID field starts with a "B". To do this, you can alter the select statement to include a where clause:
"...Where CustomerID LIKE 'B%'"
and rebind the grid. This logic can be moved in the event handler for another control - for example the checkbox check changed event. Rebinding the grid will ensure the new query is applied.
Further, with respect to the page index. The following example allows editing in a hierarchy:
http://demos.telerik.com/aspnet-ajax/grid/examples/dataediting/threelevel/defaultcs.aspx
If you go to an inner level, and go to the last page, to edit a record, the page index will be preserved. This is demonstrated in the screenshot attached to this message.
Give these suggestions a try and let me know how it goes, or if you find that I am leaving something out.
Greetings,
the Telerik team
Check out Telerik Trainer , the state of the art learning tool for Telerik products.
The second part still does not help me. I see in the sample demo that the expanded state and pagination persist, but I do not see code that actually makes this happen. They have allowautomaticupdates=true, and in my code I cannot have this as I have complex stored procedures to save my data, so I need to rebind. I am using the library submission to keep the expanded state persisted on rebind, but it does not keep the correct page index.
Thank you,
Laura
With respect to the second issue. I assume that you are rebinding the grid. In which event/where in the code, are you rebinding the grid control? I am trying to recreate the exact setup you have locally, so that I can suggest the best option.
Best wishes,
Yavor
the Telerik team
Check out Telerik Trainer , the state of the art learning tool for Telerik products.
<telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server" LoadingPanelID="RadAjaxLoadingPanel1" |
OnAjaxRequest="RadAjaxPanel1_AjaxRequest" ClientEvents-OnRequestStart="centerUpdatePanel();"> |
And here is the javascript function that creates the radwindow for editing:
function ShowEditFeedForm(id, rowIndex) { |
// get username from querystring to pass to next window |
var urlArgs = cbeGetURLArguments(); |
var userName = urlArgs.NAME; |
var sync = urlArgs.SYNC; |
var grid = $find("<%= providersGrid.ClientID %>"); |
var oWnd = window.radopen("editFeedForm.aspx?feedID=" + id + "&SYNC=" + sync + "&NAME=" + userName, "feedDialog"); |
oWnd.add_close(OnClientFeedClose); |
var oArg = new Object(); |
oArg.serviceID = id; |
//set the arguments that will be needed on the way back so they are not undefined |
oWnd.argument = oArg; |
return false; |
} |
And here is the function that is called when the window is closed:
function OnClientFeedClose(oWnd) { |
$find("<%= RadAjaxPanel1.ClientID %>").ajaxRequest(); |
} |
Which invokes the server call:
protected void RadAjaxManager1_AjaxRequest(object sender, AjaxRequestEventArgs e) |
{ |
setDataSources(); |
if ("providerDelete" == e.Argument) |
{ |
int deleted = deleteProvider(Convert.ToInt32(deleteProviderID.Text)); |
providersGrid.Rebind(); |
} |
else if ("providerDeactivate" == e.Argument) |
{ |
int deactivated = deactivateProvider(Convert.ToInt32(deleteProviderID.Text)); |
providersGrid.Rebind(); |
} |
else if ("serviceDelete" == e.Argument) |
{ |
int deleted = deleteService(Convert.ToInt32(deleteServiceID.Text)); |
providersGrid.Rebind(); |
} |
else if ("serviceDeactivate" == e.Argument) |
{ |
int deactivated = deactivateService(Convert.ToInt32(deleteServiceID.Text)); |
providersGrid.Rebind(); |
} |
else if ("feedDelete" == e.Argument) |
{ |
int deleted = deleteFeed(Convert.ToInt32(deleteFeedID.Text)); |
providersGrid.Rebind(); |
} |
else if ("feedDeactivate" == e.Argument) |
{ |
int deactivated = deactivateFeed(Convert.ToInt32(deleteFeedID.Text)); |
providersGrid.Rebind(); |
} |
else if ("Services" == e.Argument) |
{ |
providersGrid.Rebind(); |
} |
else |
providersGrid.Rebind(); |
} |
Hope this gives you a better understanding of what I am doing.
Thanks,
Laura
Attached to this message, is a small application, which handles a similar task.
I hope it helps.
Sincerely yours,
Yavor
the Telerik team
Check out Telerik Trainer , the state of the art learning tool for Telerik products.
How does this help me accomplish what I need? I see you have this in the buttonclick event handler. Should this go in my ajaxrequest before I rebind, and what should I set the current page index to? I am sorry that I am not totally understanding how this solution fits in with my current needs.
I will prepare another sample, which matches closely your setup, and attach it to this message shortly.
Kind regards,
Yavor
the Telerik team
Check out Telerik Trainer , the state of the art learning tool for Telerik products.
Actually, since the setup on your end is not a trivial one, the best option, in order to make sure I do not leave anything out, would be if you open a formal support ticket, and send me a small working project, demonstrating your present implementation. I will review the setup, and get back to you with a precise suggestion.
Regards,
Yavor
the Telerik team
Check out Telerik Trainer , the state of the art learning tool for Telerik products.