can't expand (and keep expanded), the detail table for my radgrid. - client-side

I'm using a telerik radgrid. I want to expand the item that is currently being edited to show detail. I have created a function to fire when the OnCommand event occurs. What happens is the details expand, and then contract again! It doesn't matter how I set the HierarchyLoadMode for the master or details, I've tried every setting I can think of and it still won't stay expanded when the master data item goes into edit mode.
<%# Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true"
CodeBehind="Users.aspx.cs" Inherits="WebCallManagerData.Account.Users" %>
<%# Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
<script type="text/javascript">
function OnCommand(sender, args)
{
if (args.get_commandName() == 'Edit')
{
rowIndex = args.get_commandArgument();
var radGrid = $find("<%= rgUsers.ClientID %>");
var dataItem = radGrid.get_masterTableView().get_dataItems()[rowIndex];
dataItem.set_expanded(true);
}
else if (args.get_commandName() == 'ExpandCollapse')
{
//dumpObject(args);
}
}
</script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<asp:Label ForeColor="Red" Text="" ID="DisplayMessage1" runat="server" />
<telerik:RadAjaxManagerProxy ID="RadAjaxManagerProxy1" runat="server">
<AjaxSettings>
<telerik:AjaxSetting AjaxControlID="rgUsers">
</telerik:AjaxSetting>
</AjaxSettings>
</telerik:RadAjaxManagerProxy>
<telerik:RadGrid ID="rgUsers" runat="server" CellSpacing="0" DataSourceID="odsUsers"
GridLines="None" AutoGenerateColumns="False">
<ClientSettings>
<ClientEvents OnCommand="OnCommand" />
<Selecting CellSelectionMode="None"></Selecting>
</ClientSettings>
<MasterTableView DataSourceID="odsUsers" AllowAutomaticDeletes="True" AllowAutomaticInserts="True"
AllowAutomaticUpdates="True" DataKeyNames="UserName" HierarchyLoadMode="Client">
<DetailTables>
<telerik:GridTableView runat="server" DataSourceID="odsUserRole" AllowAutomaticUpdates="True"
AutoGenerateColumns="True" EditMode="EditForms" HierarchyLoadMode="Client">
<ParentTableRelation>
<telerik:GridRelationFields DetailKeyField="UserName" MasterKeyField="UserName" />
</ParentTableRelation>
<CommandItemSettings ExportToPdfText="Export to PDF" />
<RowIndicatorColumn FilterControlAltText="Filter RowIndicator column">
</RowIndicatorColumn>
<ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column">
</ExpandCollapseColumn>
<Columns>
<telerik:GridEditCommandColumn ButtonType="ImageButton" FilterControlAltText="Filter EditCommandColumn column">
</telerik:GridEditCommandColumn>
</Columns>
<EditFormSettings>
<EditColumn FilterControlAltText="Filter EditCommandColumn column" UniqueName="EditCommandColumn1">
</EditColumn>
</EditFormSettings>
</telerik:GridTableView>
</DetailTables>
<CommandItemSettings ExportToPdfText="Export to PDF"></CommandItemSettings>
<RowIndicatorColumn FilterControlAltText="Filter RowIndicator column">
<HeaderStyle Width="20px"></HeaderStyle>
</RowIndicatorColumn>
<ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column" Visible="True">
<HeaderStyle Width="20px"></HeaderStyle>
</ExpandCollapseColumn>
<Columns>
<telerik:GridEditCommandColumn ButtonType="ImageButton" FilterControlAltText="Filter EditCommandColumn column">
</telerik:GridEditCommandColumn>
<telerik:GridBoundColumn DataField="UserName" FilterControlAltText="Filter UserName column"
HeaderText="UserName" SortExpression="UserName" UniqueName="UserName">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Email" FilterControlAltText="Filter Email column"
HeaderText="Email" SortExpression="Email" UniqueName="Email">
</telerik:GridBoundColumn>
<telerik:GridCheckBoxColumn DataField="Approved" DataType="System.Boolean" FilterControlAltText="Filter Approved column"
HeaderText="Approved" SortExpression="Approved" UniqueName="Approved">
</telerik:GridCheckBoxColumn>
<telerik:GridCheckBoxColumn DataField="LockedOut" DataType="System.Boolean" FilterControlAltText="Filter LockedOut column"
HeaderText="LockedOut" SortExpression="LockedOut" UniqueName="LockedOut">
</telerik:GridCheckBoxColumn>
<telerik:GridBoundColumn DataField="Creation" FilterControlAltText="Filter Creation column"
HeaderText="Creation" SortExpression="Creation" UniqueName="Creation" DataType="System.DateTime">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="LastLogin" DataType="System.DateTime" FilterControlAltText="Filter LastLogin column"
HeaderText="LastLogin" SortExpression="LastLogin" UniqueName="LastLogin">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="LastActivity" DataType="System.DateTime" FilterControlAltText="Filter LastActivity column"
HeaderText="LastActivity" SortExpression="LastActivity" UniqueName="LastActivity">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="LastPasswordChanged" DataType="System.DateTime"
FilterControlAltText="Filter LastPasswordChanged column" HeaderText="LastPasswordChanged"
SortExpression="LastPasswordChanged" UniqueName="LastPasswordChanged">
</telerik:GridBoundColumn>
<telerik:GridCheckBoxColumn DataField="Online" DataType="System.Boolean" FilterControlAltText="Filter Online column"
HeaderText="Online" SortExpression="Online" UniqueName="Online">
</telerik:GridCheckBoxColumn>
<telerik:GridBoundColumn DataField="Password" FilterControlAltText="Filter Password column"
HeaderText="Password" SortExpression="Password" UniqueName="Password">
</telerik:GridBoundColumn>
</Columns>
<EditFormSettings>
<EditColumn FilterControlAltText="Filter EditCommandColumn column">
</EditColumn>
</EditFormSettings>
</MasterTableView>
<FilterMenu EnableImageSprites="False">
</FilterMenu>
<HeaderContextMenu CssClass="GridContextMenu GridContextMenu_Default">
</HeaderContextMenu>
</telerik:RadGrid>
<asp:ObjectDataSource ID="odsUserRole" runat="server" SelectMethod="GetUserRoles"
TypeName="WebCallManagerData.Account.MemberShipHelper.User" OldValuesParameterFormatString="original_{0}"
UpdateMethod="UpdateUserRoles">
<SelectParameters>
<asp:Parameter DefaultValue="" Name="UserName" Type="String" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="ur" Type="Object" />
<asp:Parameter Name="UserName" Type="String" />
</UpdateParameters>
</asp:ObjectDataSource>
<asp:ObjectDataSource ID="odsUsers" runat="server" SelectMethod="GetAllUsers" TypeName="WebCallManagerData.Account.MemberShipHelper.User">
</asp:ObjectDataSource>
</asp:Content>

Related

Adding template column to radgrid causes a grid UI issue

Here is my grid, When i remove the template button the grid functions well, but when the template button is included the grid does not load well and the ui is somewhat destroyed, all the data appears in a chained string inside a box when the template button is in place:
<telerik:RadGrid OnItemCreated="gvClients_ItemCreated" runat="server" ID="gvClients" ClientSettings-EnablePostBackOnRowClick="true" CellSpacing="0" GridLines="None" Skin="Glow" DataSourceID="SqlDataSource1" AllowPaging="True" AllowSorting="True" OnSelectedIndexChanged="gvClients_SelectedIndexChanged" OnDataBound="gvClients_DataBound" AutoGenerateColumns="False">
<ClientSettings>
<Selecting AllowRowSelect="True" />
</ClientSettings>
<MasterTableView DataKeyNames="id" DataSourceID="SqlDataSource1" HierarchyLoadMode="Client">
<Columns>
<telerik:GridBoundColumn DataField="seniorId" DataType="System.Int32" FilterControlAltText="Filter seniorId column" HeaderText="seniorId" SortExpression="seniorId" UniqueName="seniorId" Visible="False">
<ColumnValidationSettings>
<ModelErrorMessage Text="" />
</ColumnValidationSettings>
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="id" DataType="System.Int32" FilterControlAltText="Filter id column" HeaderText="תעדות זהות" ReadOnly="True" SortExpression="id" UniqueName="id">
<ColumnValidationSettings>
<ModelErrorMessage Text="" />
</ColumnValidationSettings>
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="password" FilterControlAltText="Filter password column" HeaderText="סיסמא" SortExpression="password" UniqueName="password">
<ColumnValidationSettings>
<ModelErrorMessage Text="" />
</ColumnValidationSettings>
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="fName" FilterControlAltText="Filter fName column" HeaderText="שם פרטי" SortExpression="fName" UniqueName="fName">
<ColumnValidationSettings>
<ModelErrorMessage Text="" />
</ColumnValidationSettings>
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="lName" FilterControlAltText="Filter lName column" HeaderText="שם משפחה" SortExpression="lName" UniqueName="lName">
<ColumnValidationSettings>
<ModelErrorMessage Text="" />
</ColumnValidationSettings>
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="mPhone" FilterControlAltText="Filter mPhone column" HeaderText="מספר טלפון" SortExpression="mPhone" UniqueName="mPhone">
<ColumnValidationSettings>
<ModelErrorMessage Text="" />
</ColumnValidationSettings>
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="address" FilterControlAltText="Filter address column" HeaderText="כתובת" SortExpression="address" UniqueName="address">
<ColumnValidationSettings>
<ModelErrorMessage Text="" />
</ColumnValidationSettings>
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="sc" DataType="System.Byte" FilterControlAltText="Filter sc column" HeaderText="sc" SortExpression="sc" UniqueName="sc" Visible="False">
<ColumnValidationSettings>
<ModelErrorMessage Text="" />
</ColumnValidationSettings>
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="email" FilterControlAltText="Filter email column" HeaderText="אימייל" SortExpression="email" UniqueName="email">
<ColumnValidationSettings>
<ModelErrorMessage Text="" />
</ColumnValidationSettings>
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="dateJoined" DataFormatString="{0:HH:mm dd-MM-yyyy}" DataType="System.DateTime" FilterControlAltText="Filter dateJoined column" HeaderText="תאריך הצטרפות" SortExpression="dateJoined" UniqueName="dateJoined">
<ColumnValidationSettings>
<ModelErrorMessage Text="" />
</ColumnValidationSettings>
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="contract" FilterControlAltText="Filter contract column" HeaderText="קובץ חוזה" SortExpression="contract" UniqueName="contract">
<ColumnValidationSettings>
<ModelErrorMessage Text="" />
</ColumnValidationSettings>
</telerik:GridBoundColumn>
<telerik:GridTemplateColumn FilterControlAltText="Filter TemplateColumn column" HeaderText="הורד קובץ" UniqueName="downloadbutton">
<ItemTemplate>
<telerik:RadButton ID="btnDownload" runat="server" Skin="Glow" Text="הורד קובץ" CommandArgument="<%#Container.ItemIndex %>" OnCommand="btnDownload_Command">
</telerik:RadButton>
</ItemTemplate>
</telerik:GridTemplateColumn>
</Columns>
<PagerStyle AlwaysVisible="True" />
</MasterTableView>
I do not know what the problem is but after creating a new solution and copying the same source files to the new solution the problem seems to have solved itself.
Thanks anyways!
I added the templatecolumn just like below (without btnDownload_Command) and it rendered correctly. Could it be the special characters used in Text propery?
<telerik:GridTemplateColumn FilterControlAltText="Filter TemplateColumn column" HeaderText="t" UniqueName="downloadbutton">
<ItemTemplate>
<telerik:RadButton ID="btnDownload" runat="server" Text="HeaderName" CommandArgument="<%#Container.ItemIndex %>" >
</telerik:RadButton>
</ItemTemplate>
</telerik:GridTemplateColumn>

radgrid data disappear after filtering

I am using a RadGrid to show some data and I have set AllowFilteringByColumn to true, but when I try to filter rows, a postback occurs and my RadGrid content disappears (all the things disappear and just a border remains).
<telerik:RadAjaxPanel ID="pnlShowGrid" runat="server" LoadingPanelID="RadAjaxLoadingPanel4">
<div class="row-fluid">
<telerik:RadGrid ID="RadGrid1" runat="server"
CssClass="RadGrid" Height="400px"
ClientSettings-Selecting-AllowRowSelect="true"
AllowPaging="True" PageSize="20" AllowSorting="True"
AutoGenerateColumns="False" AllowAutomaticUpdates="True"
ShowStatusBar="True" AllowAutomaticDeletes="True"
AllowFilteringByColumn="True"
Width="100%"
OnUpdateCommand="RadGrid1_UpdateCommand"
OnItemDeleted="rgrd_Edit_ItemDeleted"
OnItemCommand="RadGrid1_ItemCommand">
<ExportSettings ExportOnlyData="True">
<Pdf DefaultFontFamily="Arial Unicode MS" FontType="Embed" />
<Excel AutoFitImages="True" />
</ExportSettings>
<FilterMenu EnableImageSprites="true">
</FilterMenu>
<ExportSettings ExportOnlyData="true" OpenInNewWindow="true">
<Excel Format="ExcelML"></Excel>
<Excel AutoFitImages="true" />
<Pdf FontType="Embed" AllowPrinting="true" />
<Pdf DefaultFontFamily="Arial Unicode MS" />
</ExportSettings>
<ClientSettings AllowGroupExpandCollapse="True" Selecting-AllowRowSelect="true">
<Selecting AllowRowSelect="True" />
</ClientSettings>
<MasterTableView
CommandItemDisplay="TopAndBottom" Dir="RTL" AllowFilteringByColumn="true"
DataKeyNames="AccessPesrmission_ID"
NoDetailRecordsText="??? ?????? ???? ????? !"
NoMasterRecordsText="??? ?????? ???? ????? !">
<CommandItemSettings ExportToPdfText="Export to PDF" AddNewRecordText="????? ????? ????" ShowAddNewRecordButton="false" RefreshText="?????????" ShowExportToExcelButton="true" ShowExportToWordButton="true" ShowExportToPdfButton="false">
</CommandItemSettings>
<RowIndicatorColumn FilterControlAltText="Filter RowIndicator column" FilterControlWidth="20%"></RowIndicatorColumn>
<ExpandCollapseColumn Visible="True" FilterControlAltText="Filter ExpandColumn column" FilterControlWidth="20%"></ExpandCollapseColumn>
<Columns>
<telerik:GridBoundColumn Display="false" FilterControlWidth="10px" DataField="AccessPesrmission_ID" DataType="System.Int32" FilterControlAltText="Filter AccessPesrmission_ID column" HeaderText="?????" SortExpression="AccessPesrmission_ID" UniqueName="AccessPesrmission_ID" AndCurrentFilterFunction="Contains" AutoPostBackOnFilter="True" CurrentFilterFunction="Contains">
</telerik:GridBoundColumn>
<telerik:GridCheckBoxColumn DataField="AccessPermission_Read" DataType="System.Boolean" FilterControlAltText="Filter AccessPermission_Read column" HeaderText="?????" SortExpression="AccessPermission_Read" UniqueName="AccessPermission_Read" AndCurrentFilterFunction="Contains" AutoPostBackOnFilter="True" CurrentFilterFunction="Contains">
</telerik:GridCheckBoxColumn>
<telerik:GridCheckBoxColumn DataField="AccessPermission_Add" DataType="System.Boolean" FilterControlAltText="Filter AccessPermission_Add column" HeaderText="???" SortExpression="AccessPermission_Add" UniqueName="AccessPermission_Add">
</telerik:GridCheckBoxColumn>
<telerik:GridCheckBoxColumn DataField="AccessPermission_Edit" DataType="System.Boolean" FilterControlAltText="Filter AccessPermission_Edit column" HeaderText="??????" SortExpression="AccessPermission_Edit" UniqueName="AccessPermission_Edit">
</telerik:GridCheckBoxColumn>
<telerik:GridCheckBoxColumn DataField="AccessPermission_Delete" DataType="System.Boolean" FilterControlAltText="Filter AccessPermission_Delete column" HeaderText="???" SortExpression="AccessPermission_Delete" UniqueName="AccessPermission_Delete">
</telerik:GridCheckBoxColumn>
<telerik:GridBoundColumn Display="false" FilterControlWidth="10px" DataField="AccessPesrmission_SatheSazmani_ID" FilterControlAltText="Filter AccessPesrmission_SatheSazmani_ID column" HeaderText="????? ??? ???????" SortExpression="AccessPesrmission_SatheSazmani_ID" UniqueName="AccessPesrmission_SatheSazmani_ID" AndCurrentFilterFunction="Contains" AutoPostBackOnFilter="True" CurrentFilterFunction="Contains">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn FilterControlWidth="40px" DataField="VahedSazmani_FarsiName" FilterControlAltText="Filter VahedSazmani_FarsiName column" HeaderText="???? ???????" SortExpression="VahedSazmani_FarsiName" UniqueName="VahedSazmani_FarsiName">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn FilterControlWidth="40px" DataField="Semat_Name" FilterControlAltText="Filter Semat_Name column" HeaderText="???" SortExpression="Semat_Name" UniqueName="Semat_Name">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn FilterControlWidth="40px" DataField="GrooheKarmandi_NameFarsi" FilterControlAltText="Filter GrooheKarmandi_NameFarsi column" HeaderText="???? ???????" SortExpression="GrooheKarmandi_NameFarsi" UniqueName="GrooheKarmandi_NameFarsi">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn FilterControlWidth="40px" DataField="Personel_NameKamel" FilterControlAltText="Filter Personel_NameKamel column" HeaderText="?????" SortExpression="Personel_NameKamel" UniqueName="Personel_NameKamel">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn FilterControlWidth="40px" DataField="COM_Name" FilterControlAltText="Filter COM_Name column" HeaderText="????" SortExpression="COM_Name" UniqueName="COM_Name">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn FilterControlWidth="70px" DataField="Source_Desc" FilterControlAltText="Filter Source_Desc column" HeaderText="????" SortExpression="Source_Desc" UniqueName="Source_Desc">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn FilterControlWidth="20px" DataField="SourceType_Desc" FilterControlAltText="Filter SourceType_Desc column" HeaderText="??? ????" SortExpression="SourceType_Desc" UniqueName="SourceType_Desc">
</telerik:GridBoundColumn>
<telerik:GridButtonColumn CommandName="Delete" ButtonType="ImageButton" Text="???"
UniqueName="columnDelete" ConfirmText="??? ?? ?????? ????? ???? ??? ?? ??? ???? ?"
ConfirmDialogType="RadWindow" ImageUrl="../../assets/img/icon/del-layer.png"
ConfirmDialogHeight="180" ConfirmDialogWidth="380" FooterStyle-Width="60px"
HeaderStyle-Width="60px" ItemStyle-Width="60px">
</telerik:GridButtonColumn>
<telerik:GridButtonColumn CommandName="Edit" AndCurrentFilterFunction="Contains"
ButtonType="ImageButton" ImageUrl="../../assets/img/icon/edit.png"
AutoPostBackOnFilter="True" CurrentFilterFunction="Contains" Text="??????"
FooterStyle-Width="60px" HeaderStyle-Width="60px" ItemStyle-Width="60px"
UniqueName="columnEdit">
</telerik:GridButtonColumn>
</Columns>
<EditFormSettings InsertCaption="????? ????? ????" CaptionFormatString="?????? ???? ?? ?? : {0}"
CaptionDataField="COM_ID" EditFormType="Template" PopUpSettings-Modal="true" FormTableStyle-HorizontalAlign="Center" FormCaptionStyle-HorizontalAlign="Center" PopUpSettings-CloseButtonToolTip="????" UserControlName="popupform" PopUpSettings-Width="800">
<EditColumn UniqueName="EditCommandColumn1" FilterControlAltText="Filter EditCommandColumn1 column"></EditColumn>
<FormTableStyle HorizontalAlign="Center"></FormTableStyle>
<FormCaptionStyle HorizontalAlign="Center"></FormCaptionStyle>
<FormTemplate>
</FormTemplate>
<PopUpSettings Modal="True" Width="800px" CloseButtonToolTip="????"></PopUpSettings>
</EditFormSettings>
<PagerStyle PageSizeControlType="RadComboBox"></PagerStyle>
</MasterTableView>
<PagerStyle PageSizeControlType="RadComboBox" />
</telerik:RadGrid>
</div>
<asp:SqlDataSource ID="SqlDataSource_Grid" runat="server" ConnectionString="<%$ ConnectionStrings:PigisConnectionString %>">
<SelectParameters>
<asp:ControlParameter ControlID="ddlCompany" Name="COM_ID" PropertyName="SelectedValue" Type="String" />
<asp:ControlParameter ControlID="ddlVahedSazmani" Name="VahedSazmani_ID" PropertyName="SelectedValue" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
</telerik:RadAjaxPanel>
I load data to the RadGrid with the below function. (I call the function in page load)
void LoadData()
{
SqlDataSource_Grid.SelectParameters.Clear();
SqlDataSource_Grid.SelectCommand = "spSCT_Select_From_SCT_AccessPermission";
SqlDataSource_Grid.DataBind();
RadGrid1.DataSource = SqlDataSource_Grid;
RadGrid1.Rebind();
}
Please add NeedDatasource event in your radgrid.
<telerik:RadGrid runat="server" ID="RadGrid1" OnNeedDataSource="RadGrid1_NeedDataSource">
</telerik:RadGrid>
Your C# code:
protected void RadGrid1_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
SqlDataSource_Grid.SelectParameters.Clear();
SqlDataSource_Grid.SelectCommand = "spSCT_Select_From_SCT_AccessPermission";
SqlDataSource_Grid.DataBind();
RadGrid1.DataSource = SqlDataSource_Grid;
}
It will automatically rebind/databind your radgrid whenever its needed. please check below link for more information.
Commands that invoke Rebind() implicitly
You need to use the RadGrid1_NeedDataSource method where you tell your grid what his datasource should be AND also make sure that you call a Radgrid1.Rebind() at the end of your action method

No add functionality in Telerik RadGrid

I have added Telerik GridView and linked it to my local sql server database. The problem is I can't see any add/insert row functionality and neither can I find the options to enable it. Here's the RadGrid code:
<telerik:RadGrid ID="RadGrid1" runat="server" AllowAutomaticInserts="True" AllowFilteringByColumn="True"
AllowPaging="True" AllowSorting="True" AutoGenerateDeleteColumn="True" AutoGenerateEditColumn="True"
CellSpacing="0" DataSourceID="SqlDataSource1" GridLines="None" Skin="Silk" Width="987px">
<ExportSettings ExportOnlyData="True" OpenInNewWindow="True">
<Pdf AllowAdd="True" AllowCopy="True" />
</ExportSettings>
<MasterTableView autogeneratecolumns="False" datakeynames="Id" datasourceid="SqlDataSource1">
<CommandItemSettings ExportToPdfText="Export to PDF"></CommandItemSettings>
<RowIndicatorColumn Visible="True" FilterControlAltText="Filter RowIndicator column">
<HeaderStyle Width="20px"></HeaderStyle>
</RowIndicatorColumn>
<ExpandCollapseColumn Visible="True" FilterControlAltText="Filter ExpandColumn column">
<HeaderStyle Width="20px"></HeaderStyle>
</ExpandCollapseColumn>
<Columns>
<telerik:GridBoundColumn DataField="Id" DataType="System.Int32" FilterControlAltText="Filter Id column"
HeaderText="Id" ReadOnly="True" SortExpression="Id" UniqueName="Id">
<ColumnValidationSettings>
<ModelErrorMessage Text="" />
</ColumnValidationSettings>
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Name" FilterControlAltText="Filter Name column" HeaderText="Name"
SortExpression="Name" UniqueName="Name">
<ColumnValidationSettings>
<ModelErrorMessage Text="" />
</ColumnValidationSettings>
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Form" FilterControlAltText="Filter Form column" HeaderText="Form"
SortExpression="Form" UniqueName="Form">
<ColumnValidationSettings>
<ModelErrorMessage Text="" />
</ColumnValidationSettings>
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Price" FilterControlAltText="Filter Price column" HeaderText="Price"
SortExpression="Price" UniqueName="Price">
<ColumnValidationSettings>
<ModelErrorMessage Text="" />
</ColumnValidationSettings>
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Expiry" DataType="System.DateTime" FilterControlAltText="Filter Expiry
column" HeaderText="Expiry" SortExpression="Expiry" UniqueName="Expiry">
<ColumnValidationSettings>
<ModelErrorMessage Text="" />
</ColumnValidationSettings>
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Quantity" DataType="System.Int32" FilterControlAltText="Filter Quantity
column" HeaderText="Quantity" SortExpression="Quantity" UniqueName="Quantity">
<ColumnValidationSettings>
<ModelErrorMessage Text="" />
</ColumnValidationSettings>
</telerik:GridBoundColumn>
</Columns>
<EditFormSettings>
<EditColumn FilterControlAltText="Filter EditCommandColumn column"></EditColumn>
</EditFormSettings>
<PagerStyle PageSizeControlType="RadComboBox" Mode="Slider"></PagerStyle>
</MasterTableView>
<PagerStyle PageSizeControlType="RadComboBox" Mode="Slider"></PagerStyle>
<FilterMenu EnableImageSprites="False"></FilterMenu>
</telerik:RadGrid>
You can either add it directly in the aspx like this:
<telerik:RadGrid runat="server" ID="RadGrid1" AllowPaging="True"
AllowSorting="True"
AutoGenerateColumns="False"
AllowAutomaticInserts="True"
AllowAutomaticUpdates="True"
AllowAutomaticDeletes="True" ShowStatusBar="True"
.........
or alternatively in the wizard as per picture, select master page and flag the options:
Moreover, make sure you generate the needed CRUD when you define the parameters of the sqlconnection (advanced menu, generate CRUD instructions). I do not see them in your code.
In step 2 of this article you will find detail on how to do it.

How to insert LINQ where parameter in cde behind

I want to add a dropdownlist fro user
to select All records, coming 2 months, etc.
and then refresh the gridview.
How can i add the where parameter to linqdatasource by code behind ?
<telerik:RadDropDownList ID="rdl_filter_date" runat="server" OnSelectedIndexChanged="rdl_filter_date_SelectedIndexChanged">
<Items>
<telerik:DropDownListItem Text="All" Value="all" />
<telerik:DropDownListItem Text="Coming 2 months" Value="2mths" />
</Items>
</telerik:RadDropDownList>
<telerik:RadGrid ID="RadGrid1" runat="server" CellSpacing="0" AutoGenerateColumns="False"
DataSourceID="LDS_UpcomingTraining" GridLines="None" Width="700">
<MasterTableView AutoGenerateColumns="False" DataSourceID="LDS_UpcomingTraining">
<CommandItemSettings ExportToPdfText="Export to PDF"></CommandItemSettings>
<RowIndicatorColumn Visible="True" FilterControlAltText="Filter RowIndicator column">
<HeaderStyle Width="20px"></HeaderStyle>
</RowIndicatorColumn>
<ExpandCollapseColumn Visible="True" FilterControlAltText="Filter ExpandColumn column">
<HeaderStyle Width="20px"></HeaderStyle>
</ExpandCollapseColumn>
<Columns>
<telerik:GridBoundColumn DataField="db_course.Course_Name"
FilterControlAltText="Filter Course Name"
HeaderText="Course Name" SortExpression="db_course.Course_Name"
UniqueName="db_course.Course_Name" ReadOnly="True">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Start_Time" DataType="System.DateTime"
FilterControlAltText="Filter Start_Time column" HeaderText="Start Time"
ReadOnly="True" SortExpression="Start_Time" UniqueName="Start_Time" DataFormatString="{0:dd-MMM-yyyy hh:mm tt}">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="End_Time" DataType="System.DateTime"
FilterControlAltText="Filter End_Time column" HeaderText="End Time"
ReadOnly="True" SortExpression="End_Time" UniqueName="End_Time" DataFormatString="{0:dd-MMM-yyyy hh:mm tt}">
</telerik:GridBoundColumn>
<telerik:GridHyperLinkColumn Text="View" HeaderText="Online Teaching Material" DataNavigateUrlFields="db_training_session.MaterialURL" Target="_blank" UniqueName="HyperLinkColumn" AllowFiltering="false">
</telerik:GridHyperLinkColumn>
</Columns>
<EditFormSettings>
<EditColumn FilterControlAltText="Filter EditCommandColumn column"></EditColumn>
</EditFormSettings>
<PagerStyle PageSizeControlType="RadComboBox"></PagerStyle>
</MasterTableView>
<PagerStyle PageSizeControlType="RadComboBox"></PagerStyle>
<FilterMenu EnableImageSprites="False"></FilterMenu>
</telerik:RadGrid>
<asp:LinqDataSource ID="LDS_UpcomingTraining" runat="server"
ContextTypeName="dcLRDBDataContext" EntityTypeName=""
Select="new (db_Course, Start_Time, End_Time, db_Training_Session)"
TableName="db_Employee_Enrollments"
Where="UserID == #UserID && db_Training_Session.Status == #db_Training_Session and Start_Time >= DateTime.Now" OrderBy="Start_Time">
<WhereParameters>
<asp:SessionParameter Name="UserID" SessionField="UserID" Type="Int32" />
<asp:Parameter DefaultValue="Confirmed" Name="db_Training_Session"
Type="String" />
</WhereParameters>
</asp:LinqDataSource>
Code behind
Protected Sub rdl_filter_date_SelectedIndexChanged(ByVal sender As Object, ByVal e As Telerik.Web.UI.DropDownListEventArgs) Handles rdl_filter_date.SelectedIndexChanged
If rdl_filter_date.SelectedValue = "2mths" Then
ElseIf rdl_filter_date.SelectedValue = "all" Then
End If
End Sub
You can set that even in .aspx:
(you'll have to modify Where condition based on param)
<asp:LinqDataSource runat="server" ...>
...
<WhereParameters>
<asp:ControlParameter ControlID="rdl_filter_date" Name="Param" PropertyName="SelectedValue" />
</WhereParameters>
</asp:LinqDataSource>
Second option - use codebehind to set it all. Markup:
<asp:LinqDataSource ID="lds" runat="server" OnSelecting="lds_Selecting" />
Codebehind:
protected void lds_Selecting(object sender, LinqDataSourceSelectEventArgs e) {
var query = ...; // make your query here
e.Result = query;
}

Telerik RadGrid + RadAjaxManager

Let's go straight to the problem.
I have two gridviews from which one generates the data source to another one. Both gridviews have ability to edit the item (row), but editing only works in first gridview (the one that generates data for the other one), when I click on edit in the second gridview nothing happens. I've been searching the web for a while and (I believe) found out that what I need is AJAX Manager.
I've checked couple of examples/Demos from Telerik's site, but I'm still not sure how to make editing in the second gridview work. When I click "Edit" button in second gridview nothing happens at all.
Both gridviews have edit forms inside and both gridview's edit form types are "WebUserControl".
Currently RadAjaxManager looks like this:
<telerik:RadAjaxManager ID="ramAsseti" runat="server">
<AjaxSettings>
<telerik:AjaxSetting AjaxControlID="gvKontakti">
<UpdatedControls>
<telerik:AjaxUpdatedControl ControlID="gvAsseti" />
</UpdatedControls>
</telerik:AjaxSetting>
</AjaxSettings>
</telerik:RadAjaxManager>
Could someone help me out with some suggestions. Any help would be appreciated.
EDIT: In the meantime I've added one more RadGrid and updated RadAjaxManager and what I got is that first two RadGrids work (by "work" I mean I can click Edit and UserControls are displayed), but the last one doesn't work. For some strange reason Delete function does work in the last RadGrid (gvAsseti).
Here is the code (skip boundfields as they work fine):
<telerik:RadScriptManager ID="RadScriptManager1" runat="server">
</telerik:RadScriptManager>
<telerik:RadAjaxManager ID="ramAsseti" runat="server">
<AjaxSettings>
<telerik:AjaxSetting AjaxControlID="gvTvrtke">
<UpdatedControls>
<telerik:AjaxUpdatedControl ControlID="gvTvrtke" />
<telerik:AjaxUpdatedControl ControlID="gvKontakti" />
<telerik:AjaxUpdatedControl ControlID="gvAsseti" />
</UpdatedControls>
</telerik:AjaxSetting>
</AjaxSettings>
</telerik:RadAjaxManager>
<telerik:RadGrid ID="gvTvrtke" runat="server" AllowPaging="True" AllowSorting="True"
AutoGenerateColumns="False" CellSpacing="0" GridLines="None" OnNeedDataSource="gvTvrtke_NeedDataSource"
OnItemCommand="gvTvrtke_ItemCommand">
<MasterTableView DataKeyNames="idFirma" CommandItemDisplay="TopAndBottom" InsertItemPageIndexAction="ShowItemOnCurrentPage">
<CommandItemSettings AddNewRecordText="Dodaj novu tvrtku" RefreshText="Osvježi" />
<Columns>
<telerik:GridButtonColumn UniqueName="ShowAssetsColumn" ButtonType="LinkButton" DataTextFormatString="Kontakti"
DataTextField="idTvrtka" CommandName="ShowContacts">
</telerik:GridButtonColumn>
<telerik:GridBoundColumn UniqueName="Naziv" DataField="Naziv" HeaderText="Naziv">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn UniqueName="OIB" HeaderText="OIB" DataField="OIB">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn UniqueName="Tel1" HeaderText="Telefon 1" DataField="Tel1">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn UniqueName="Tel2" HeaderText="Telefon 2" DataField="Tel2">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn UniqueName="Fax" HeaderText="Fax" DataField="Fax">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn UniqueName="Mob1" HeaderText="Mobitel 1" DataField="Mob1">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn UniqueName="Mob2" HeaderText="Mobitel 2" DataField="Mob2">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn UniqueName="Email1" HeaderText="E-mail 1" DataField="Email1">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn UniqueName="Email2" HeaderText="E-mail 2" DataField="Email2">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn UniqueName="Adresa1" HeaderText="Adresa" DataField="Adresa1">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn UniqueName="Web" HeaderText="Web" DataField="Web">
</telerik:GridBoundColumn>
<telerik:GridCheckBoxColumn UniqueName="Aktivan" HeaderText="Aktivan" DataField="Aktivan">
</telerik:GridCheckBoxColumn>
<telerik:GridEditCommandColumn UniqueName="EditCommandColumn">
</telerik:GridEditCommandColumn>
<telerik:GridButtonColumn UniqueName="DeleteColumn" Text="Delete" CommandName="Delete"
ConfirmDialogType="RadWindow" ConfirmText="Brisanje tvrtke!" />
</Columns>
<EditFormSettings UserControlName="UserControls/TvrtkaUserControl.ascx" EditFormType="WebUserControl">
<EditColumn UniqueName="EditCommandColumn1">
</EditColumn>
</EditFormSettings>
</MasterTableView>
</telerik:RadGrid>
<telerik:RadGrid ID="gvKontakti" runat="server" AllowPaging="True" AllowSorting="True"
AutoGenerateColumns="False" CellSpacing="0" GridLines="None" Skin="Default" OnNeedDataSource="gvKontakti_NeedDataSource"
OnDeleteCommand="gvKontakti_DeleteCommand" OnInsertCommand="gvKontakti_InsertCommand"
OnPreRender="gvKontakti_PreRender" OnUpdateCommand="gvKontakti_UpdateCommand"
OnItemCommand="gvKontakti_ItemCommand">
<MasterTableView DataKeyNames="idKontakt" CommandItemDisplay="TopAndBottom" InsertItemPageIndexAction="ShowItemOnCurrentPage">
<CommandItemSettings AddNewRecordText="Dodaj novi kontakt" RefreshText="Osvježi" />
<Columns>
<telerik:GridButtonColumn UniqueName="ShowAssetsColumn" ButtonType="LinkButton" DataTextFormatString="Asseti"
DataTextField="idKontakt" CommandName="ShowAssets">
</telerik:GridButtonColumn>
<telerik:GridBoundColumn UniqueName="Kontakt" DataField="Naziv" HeaderText="Kontakt">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn UniqueName="Funkcija" HeaderText="Funkcija" DataField="Funkcija">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn UniqueName="Tel1" HeaderText="Telefon 1" DataField="Tel1">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn UniqueName="Tel2" HeaderText="Telefon 2" DataField="Tel2">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn UniqueName="Mob1" HeaderText="Mobitel 1" DataField="Mob1">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn UniqueName="Mob2" HeaderText="Mobitel 2" DataField="Mob2">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn UniqueName="Email1" HeaderText="E-mail 1" DataField="Email1">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn UniqueName="Email2" HeaderText="E-mail 2" DataField="Email2">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn UniqueName="Fax" HeaderText="Fax" DataField="Fax">
</telerik:GridBoundColumn>
<telerik:GridCheckBoxColumn UniqueName="Aktivan" HeaderText="Aktivan" DataField="Aktivan">
</telerik:GridCheckBoxColumn>
<telerik:GridEditCommandColumn UniqueName="EditCommandColumn">
</telerik:GridEditCommandColumn>
<telerik:GridButtonColumn UniqueName="DeleteColumn" Text="Delete" CommandName="Delete"
ConfirmDialogType="RadWindow" ConfirmText="Brisanje kontakta!" />
</Columns>
<EditFormSettings UserControlName="UserControls/KontaktUserControl.ascx" EditFormType="WebUserControl">
<EditColumn UniqueName="EditCommandColumn1">
</EditColumn>
</EditFormSettings>
</MasterTableView>
</telerik:RadGrid>
<telerik:RadGrid ID="gvAsseti" runat="server" OnNeedDataSource="gvAsseti_NeedDataSource"
AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" CellSpacing="0"
GridLines="None" ondeletecommand="gvAsseti_DeleteCommand"
oninsertcommand="gvAsseti_InsertCommand"
onupdatecommand="gvAsseti_UpdateCommand">
<MasterTableView DataKeyNames="idAsset" CommandItemDisplay="TopAndBottom" InsertItemPageIndexAction="ShowItemOnCurrentPage">
<CommandItemSettings AddNewRecordText="Dodaj novi asset" RefreshText="Prikaži sve assete" />
<Columns>
<telerik:GridBoundColumn UniqueName="Naziv" DataField="Naziv" HeaderText="Naziv">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn UniqueName="Kod1" HeaderText="Kod 1" DataField="Kod1">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn UniqueName="Kod2" HeaderText="Kod 2" DataField="Kod">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn UniqueName="DatumGarancije" HeaderText="Datum garancije"
DataField="DatumGarancije">
</telerik:GridBoundColumn>
<telerik:GridCheckBoxColumn UniqueName="Aktivan" HeaderText="Aktivan" DataField="Aktivan">
</telerik:GridCheckBoxColumn>
<telerik:GridEditCommandColumn UniqueName="EditCommandColumn">
</telerik:GridEditCommandColumn>
<telerik:GridButtonColumn UniqueName="DeleteColumn" Text="Delete" CommandName="Delete"
ConfirmDialogType="RadWindow" ConfirmText="Brisanje asseta!" />
</Columns>
<EditFormSettings UserControlName="UserControls/AssetUserControl.ascx" EditFormType="WebUserControl">
<EditColumn UniqueName="EditCommandColumn1">
</EditColumn>
</EditFormSettings>
</MasterTableView>
</telerik:RadGrid>
I think if you just add gvAsseti to the AJAX settings like this, it should work fine:
Instead of this:
<telerik:RadAjaxManager ID="ramAsseti" runat="server">
<AjaxSettings>
<telerik:AjaxSetting AjaxControlID="gvKontakti">
<UpdatedControls>
<!-- DON'T PUT THEM HERE -->
</UpdatedControls>
</telerik:AjaxSetting>
</AjaxSettings>
</telerik:RadAjaxManager>
Do this (notice how there is an AjaxSetting for each grid):
<telerik:RadAjaxManager ID="ramAsseti" runat="server">
<AjaxSettings>
<telerik:AjaxSetting AjaxControlID="gvKontakti" />
<telerik:AjaxSetting AjaxControlID="gvAsseti" />
<telerik:AjaxSetting AjaxControlID="gvTvrtke" />
</AjaxSettings>
</telerik:RadAjaxManager>
Another alternative is to use a RadAjaxPanel, and put all of the grids inside of it. This will ensure that everything is AJAX:
<telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server">
<telerik:RadGrid ... >
<telerik:Radgrid ... >
<telerik:RadGrid ... >
</telerik:RadAjaxPanel>

Resources