Hi There,
I have seen this topic come up before but without an answer so I thought I'd define the problem as simply as possible.
I have a LINQ command creating a query:
| var gridData = from au in dc.aspnet_Users |
| join aur in dc.aspnet_UsersInRoles |
| on au.UserId equals aur.UserId |
| join ar in dc.aspnet_Roles |
| on aur.RoleId equals ar.RoleId |
| join am in dc.aspnet_Memberships |
| on au.UserId equals am.UserId |
| select new |
| { |
| au.UserName, |
| ar.RoleName, |
| am.Email, |
| am.IsApproved, |
| am.IsLockedOut |
| }; |
THE IMPORTANT POINT IS THAT THIS USES MORE THAN 1 TABLE.
Note: This is accessing the Roles and Users tables in the standard MS Login scenario.
Then I have a simple RadGrid:
| <telerik:RadGrid ID="rgUsers" runat="server" AllowAutomaticDeletes="True" |
| AllowAutomaticUpdates="True" AutoGenerateDeleteColumn="True" |
| AutoGenerateEditColumn="True" GridLines="None"> |
| <MasterTableView EditMode="InPlace"> |
| <RowIndicatorColumn> |
| <HeaderStyle Width="20px"></HeaderStyle> |
| </RowIndicatorColumn> |
| <ExpandCollapseColumn> |
| <HeaderStyle Width="20px"></HeaderStyle> |
| </ExpandCollapseColumn> |
| </MasterTableView> |
| </telerik:RadGrid> |
Finally I bind the data to the grid in Page_Load
| rgUsers.AutoGenerateColumns = true; |
| rgUsers.DataSource = gridData.ToList(); |
| rgUsers.DataBind(); |
This will display the data from the 4 tables correctly.
However, when Edit is pressed on the Grid the fields are not editable.
I have tried the following:
1) 1) I can use a LinqDataSource that allows Edit/Update BUT only if there is only 1 table in the LINQ query.
2) 2) I can use a ObjectDataSource onto a dataset but once again this only works if the the dataset adaptor is accessing a single table.
I have looked at the variouse suggested demos and example code but they have all ignored the multiple table/Join problem:
http://demos.telerik.com/aspnet-ajax/grid/examples/dataediting/threelevel/defaultcs.aspx
I am not wedded to LINQ. I am quite happy to adapt in order to get a RadGrid that can support Update and Edit to multiple tables.
What should I do to achieve a grid that displays records composed from multiple tables with Update and Edit available?
Thanks for any help
Richard
| <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> |
| <%@ Register Assembly="Telerik.Web.UI, Version=2008.2.826.20, Culture=neutral, PublicKeyToken=121fae78165ba3d4" |
| Namespace="Telerik.Web.UI" TagPrefix="telerik" %> |
| <%@ Register Src="WebUserControl.ascx" TagName="WebUserControl" TagPrefix="uc1" %> |
| <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> |
| <html xmlns="http://www.w3.org/1999/xhtml"> |
| <head runat="server"> |
| <title>Untitled Page</title> |
| </head> |
| <body> |
| <form id="form1" runat="server"> |
| <telerik:RadScriptManager ID="ScriptManager1" runat="server" EnableTheming="True"> |
| </telerik:RadScriptManager> |
| <br /> |
| <div> |
| <asp:LinkButton ID="LinkButton1" runat="server">Show ToolTip</asp:LinkButton><br /> |
| <telerik:RadToolTipManager ID="RadToolTipManager1" runat="server" ManualClose="True" |
| Modal="True" OnAjaxUpdate="RadToolTipManager1_AjaxUpdate"> |
| <TargetControls> |
| <telerik:ToolTipTargetControl IsClientID="False" TargetControlID="LinkButton1" Value="" /> |
| </TargetControls> |
| </telerik:RadToolTipManager> |
| </div> |
| </form> |
| </body> |
| </html> |
| using System; |
| using System.Data; |
| using System.Configuration; |
| using System.Web; |
| using System.Web.Security; |
| using System.Web.UI; |
| using System.Web.UI.WebControls; |
| using System.Web.UI.WebControls.WebParts; |
| using System.Web.UI.HtmlControls; |
| public partial class _Default : System.Web.UI.Page |
| { |
| protected void Page_Load(object sender, EventArgs e) |
| { |
| } |
| protected void RadToolTipManager1_AjaxUpdate(object sender, Telerik.Web.UI.ToolTipUpdateEventArgs e) |
| { |
| WebUserControl UC = (WebUserControl)Page.LoadControl("WebUserControl.ascx"); |
| e.UpdatePanel.ContentTemplateContainer.Controls.Add(UC); |
| } |
| } |
| <%@ Control Language="C#" AutoEventWireup="true" CodeFile="WebUserControl.ascx.cs" Inherits="WebUserControl" %> |
| <%@ Register Assembly="Telerik.Web.UI, Version=2008.2.826.20, Culture=neutral, PublicKeyToken=121fae78165ba3d4" |
| Namespace="Telerik.Web.UI" TagPrefix="telerik" %> |
| <asp:Button ID="Button1" runat="server" OnClientClick="ClientClick" Text="Button in UserControl" /> |
| <script language="javascript" type="text/javascript"> |
| function ClientClick(sender, args) |
| { |
| Alert('Clicked!'); |
| } |
| </script> |

<
telerik:RadTab Text="Another Tab" AccessKey="3"> </telerik:RadTab>
| <telerik:RadAjaxManagerProxy ID="RadAjaxManagerProxy1" runat="server"> |
| <AjaxSettings> |
| <telerik:AjaxSetting AjaxControlID="gridCMs"> |
| <UpdatedControls> |
| <telerik:AjaxUpdatedControl ControlID="gridCMs" LoadingPanelID="RadAjaxLoadingPanel1" /> |
| <telerik:AjaxUpdatedControl ControlID="RadToolTipManager1" /> |
| </UpdatedControls> |
| </telerik:AjaxSetting> |
| <telerik:AjaxSetting AjaxControlID="gridInOpEquip"> |
| <UpdatedControls> |
| <telerik:AjaxUpdatedControl ControlID="gridInOpEquip" LoadingPanelID="RadAjaxLoadingPanel1" /> |
| <telerik:AjaxUpdatedControl ControlID="RadToolTipManager1" /> |
| </UpdatedControls> |
| </telerik:AjaxSetting> |
| <telerik:AjaxSetting AjaxControlID="tabMain"> |
| <UpdatedControls> |
| <telerik:AjaxUpdatedControl ControlID="gridCMs" LoadingPanelID="RadAjaxLoadingPanel1" /> |
| <telerik:AjaxUpdatedControl ControlID="gridInOpEquip" /> |
| </UpdatedControls> |
| </telerik:AjaxSetting> |
| </AjaxSettings> |
| </telerik:RadAjaxManagerProxy> |
| Protected Sub tabMain_TabClick(ByVal sender As Object, ByVal e As Telerik.Web.UI.RadTabStripEventArgs) Handles tabMain.TabClick |
| Select Case e.Tab.Value |
| Case "OpenCMs" |
| If gridCMs.Visible = False Then |
| gridCMs.Visible = True |
| gridCMs.DataBind() |
| End If |
| Case "InOpEquip" |
| If gridInOpEquip.Visible = False Then |
| gridInOpEquip.Visible = True |
| gridInOpEquip.DataBind() |
| End If |
| End Select |
| End Sub |
| //Cast EditableItem |
| GridEditableItem editedItem = e.Item as GridEditableItem; |
| //Get the ColumnEditor for the FileColumn |
| //Get the RadUpload from the ColumnEditor |
| GridAttachmentColumnEditor editor = GridAttachmentColumnEditor)editedItem.EditManager.GetColumnEditor("FileColumn"); |
| RadUpload upload = (RadUpload)editor.RadUploadControl; |
| //If file invalid, Throw an error |
| if (upload.UploadedFiles.Count == 0 && upload.InvalidFiles.Count > 0) |
| { |
| throw new Exception("Invalid File Type."); |
| } |
| //If no file found, Throw an error |
| else if (upload.UploadedFiles.Count == 0 && upload.InvalidFiles.Count == 0) |
| { |
| throw new Exception("No file to Upload."); |
| } |