tableView.AllowNaturalSort = false;tableView.OverrideDataSourceControlSorting = true;tableView.AllowSorting = false;tableView.SortExpressions.Clear(); tableView.Rebind();protected void rg_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e) { try { this.rg.VirtualItemCount = this.ItemCount; DataTable tb ; if (string.IsNullOrEmpty(sortedFieldClicked)) tb = this.DataSourceObject.GetData(this.TabId, this.rg.CurrentPageIndex + 1, this.rg.PageSize, null, SortOrder.None); else { tb = this.DataSourceObject.GetDataBySortedField(this.TabId, this.rg.CurrentPageIndex + 1, this.rg.PageSize, sortedFieldClicked, actualSortOrder); } this.rg.DataSource = tb; } catch (Exception ex) { UIProcessHelper.AddMessage(String.Format("Error while fetching data for tab '{0}' TODO List: {1}", this.TabId,ex.Message), UIMessage.UIMessageType.error); } }this.rg.DataSource = tb;
this.rg.DataSource = tb;"In my module there are 2 grids, first one is populated on the search button click.
in the grid the first column was select button, on click of that button popup window will be displayed with yes or no option.
If it is Yes then the another datasource will be binded in the 2nd grid.
If the datasource have records on click of AddNewRecord button, it display the edit form with insert and cancel buttons.
Issue:
On click of AddNewRecord option the 2nd grid is not visible when there is no datasource to bind, but it is working fine if the datasource have records. the 2nd grid will be disapper on click of any button in the grid.
Resolution Required:
Even though the data source has empty records, on click of AddNewRecord the edit form should be visible and we need to add the records in the Edit form and rebind the data in the grid.
Can u please give the solution for my issue also if you have code sample please share with me.
Thanks
RadGrid1.ID = "RadGrid1" 'RadGrid1.Width = Unit.Pixel(1500) RadGrid1.Height = Unit.Pixel(700) RadGrid1.MasterTableView.EditMode = GridEditMode.InPlace RadGrid1.AllowPaging = True RadGrid1.PagerStyle.Mode = GridPagerMode.NextPrevAndNumeric RadGrid1.AutoGenerateColumns = False RadGrid1.ShowStatusBar = True RadGrid1.AllowSorting = True RadGrid1.AllowFilteringByColumn = True RadGrid1.MasterTableView.NoDetailRecordsText = "No records could be found." RadGrid1.MasterTableView.NoMasterRecordsText = "No records could be found." RadGrid1.MasterTableView.ShowHeadersWhenNoRecords = True RadGrid1.Skin = "WebBlue" RadGrid1.HeaderStyle.CssClass = "RadGridHeader" RadGrid1.MasterTableView.ItemStyle.CssClass = "DetailsRow1" RadGrid1.MasterTableView.AlternatingItemStyle.CssClass = "DetailsRow2" RadGrid1.GroupingSettings.CaseSensitive = False RadGrid1.ClientSettings.ClientEvents.OnGridCreated = "GetGridObject" RadGrid1.ClientSettings.Scrolling.FrozenColumnsCount = 2 RadGrid1.ClientSettings.AllowColumnsReorder = True RadGrid1.ClientSettings.ColumnsReorderMethod = GridClientSettings.GridColumnsReorderMethod.Reorder RadGrid1.ClientSettings.Selecting.AllowRowSelect = True RadGrid1.ClientSettings.Resizing.AllowColumnResize = True RadGrid1.ClientSettings.Scrolling.AllowScroll = True RadGrid1.ClientSettings.Scrolling.UseStaticHeaders = True RadGrid1.ClientSettings.Scrolling.SaveScrollPosition = True RadGrid1.ClientSettings.ClientEvents.OnFilterMenuShowing = "filterMenuShowing" RadGrid1.FilterMenu.OnClientShowing = "MenuShowing" If ConfigurationManager.AppSettings("geoSelectionGridSize") <> "" Then RadGrid1.MasterTableView.PageSize = ConfigurationManager.AppSettings("geoSelectionGridSize") Else RadGrid1.MasterTableView.PageSize = 50 End If RadGrid1.MasterTableView.AllowMultiColumnSorting = True RadGrid1.MasterTableView.DataKeyNames = New String() {"DetailID", "Day", "FoundGeographies", "SubZipCount"} RadGrid1.MasterTableView.HierarchyLoadMode = GridChildLoadMode.ServerBind RadGrid1.MasterTableView.HierarchyDefaultExpanded = True Dim dpCounter As Integer = 1 Dim dpCollection As IList(Of RadListBoxItem) = rlbDistributionPatterns.CheckedItems For Each item As RadListBoxItem In dpCollection Dim columnGroup As New GridColumnGroup columnGroup.HeaderText = item.Text columnGroup.Name = "GroupDP" & dpCounter.ToString columnGroup.HeaderStyle.HorizontalAlign = HorizontalAlign.Center RadGrid1.MasterTableView.ColumnGroups.Add(columnGroup) dpCounter += 1 Next Dim strSQL As String Dim columnHeader As String = "" Dim columnName As String = "" Try strSQL = "EXEC WB_sp_RetrieveGeographySelectionColumnOrder " & UcHeader.UserId mobjSqlDataReaderColumnheaders = mobjDatabase.fnRetrieveData("DATAREADER", strSQL, "Columns") Do While mobjSqlDataReaderColumnheaders.Read columnHeader = mobjSqlDataReaderColumnheaders("ColumnHeader").ToString.Trim columnName = mobjSqlDataReaderColumnheaders("ColumnName").ToString.Trim If (columnName = "LocationMarket" Or columnName = "LocationNumber" Or columnName = "LocationName" Or columnName = "Distance" Or _ columnName = "Sales" Or columnName = "TotalSales" Or columnName = "BOS" Or columnName = "CumeBOS" Or columnName = "SPH" Or columnName = "SPHIndex") Then If miZipCodeStoreAssociationTypeID > 0 Then columnCreation(columnHeader, columnName, RadGrid1) End If ElseIf Left(columnName, 2) = "CD" Then If Right(columnName, 1) = 1 And mstrClientDataCategoryID1Description.Trim <> "" Then columnCreation(mstrClientDataCategoryID1Description.Trim, "CD1", RadGrid1) End If If Right(columnName, 1) = 2 And mstrClientDataCategoryID2Description.Trim <> "" Then columnCreation(mstrClientDataCategoryID2Description.Trim, "CD2", RadGrid1) End If If Right(columnName, 1) = 3 And mstrClientDataCategoryID3Description.Trim <> "" Then columnCreation(mstrClientDataCategoryID3Description.Trim, "CD3", RadGrid1) End If ElseIf Left(columnName, 11) = "Demographic" Then If Right(columnName, 1) = 1 And mstrReportDemographicID1Description.Trim <> "" Then columnCreation(mstrReportDemographicID1Description.Trim, "Demographic1", RadGrid1) End If If Right(columnName, 1) = 2 And mstrReportDemographicID2Description.Trim <> "" Then columnCreation(mstrReportDemographicID2Description.Trim, "Demographic2", RadGrid1) End If If Right(columnName, 1) = 3 And mstrReportDemographicID3Description.Trim <> "" Then columnCreation(mstrReportDemographicID3Description.Trim, "Demographic3", RadGrid1) End If If Right(columnName, 1) = 4 And mstrReportDemographicID4Description.Trim <> "" Then columnCreation(mstrReportDemographicID4Description.Trim, "Demographic4", RadGrid1) End If If Right(columnName, 1) = 5 And mstrReportDemographicID5Description.Trim <> "" Then columnCreation(mstrReportDemographicID5Description.Trim, "Demographic5", RadGrid1) End If ElseIf (columnName = "Forced" Or columnName = "Version" Or columnName = "SubVersionCategory" Or columnName = "DeliveryCode" Or columnName = "DistributionPatterns") Then If UcHeader.objSession.ApplicationId <> CInt(ConfigurationManager.AppSettings("MediaviewerAppID")) Then If columnName = "Forced" Then columnCreation(columnHeader, columnName, RadGrid1) End If If columnName = "Version" And miVersionsCategoryID > 0 Then columnCreation(columnHeader, columnName, RadGrid1) End If If columnName = "SubVersionCategory" And miVersionsCategoryID > 0 Then columnCreation(columnHeader, columnName, RadGrid1) End If If columnName = "DeliveryCode" And miDeliveryCodeCount > 0 Then columnCreation(columnHeader, columnName, RadGrid1) End If If columnName = "DistributionPatterns" Then dpCounter = 1 For Each item As RadListBoxItem In dpCollection columnCreation(item.Text, "DP" & dpCounter.ToString, RadGrid1) columnCreation(item.Text, "CoverageDP" & dpCounter.ToString, RadGrid1) dpCounter += 1 Next End If End If Else columnCreation(columnHeader, columnName, RadGrid1) End If Loop mobjSqlDataReaderColumnheaders.Close() mobjSqlDataReaderColumnheaders = Nothing Catch exp As Exception Throw New Exception(exp.Message & ", frmGeographySelection.defineGridStructure") End Try columnCreation("Geography", "Geography2", RadGrid1) columnCreation("Circ Type", "CirculationTypeDescription2", RadGrid1) columnCreation("FoundGeographies", "FoundGeographies", RadGrid1) RadGrid1.Width = Unit.Pixel(widthOfRadGridDetails + 40) Me.PlaceHolder1.Controls.Add(RadGrid1) For Each lItem As ListItem In chkTipologieLog.Items If lItem.Selected Then lstrFiltro += "(CodTipologiaLog = " + lItem.Value.ToString + ") OR" End If Next rdgrid.Mastertableview.FilterExpression = "(" + lstrFiltro + ")"
rdgrid.Mastertableview.rebind 
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager><div> <telerik:RadGrid ID="TGrid" runat="server" Visible="true" AllowPaging="true" AllowSorting="true" PageSize="20" ScrollHeight="100px" ViewStateMode="Enabled" OnNeedDataSource="RadGrid1_NeedDataSource" OnPreRender="RadGrid1_PreRender" AutoGenerateColumns="false" AllowSelection="False" AllowMultiRowSelection="false" AllowMultiRowEdit="true" > <MasterTableView runat="server" HeaderStyle-Wrap="False" AllowCustomSorting="true" AllowMultiColumnSorting="false" RetrieveAllDataFields="false" EnableColumnsViewState="false" EditFormSettings-EditColumn-Visible="false" AdditionalDataFieldNames="Cow_ID" DataKeyNames="Cow_ID" EditMode="InPlace"> <Columns> <telerik:GridBoundColumn DataField="Cow_ID" HeaderText="MiHub ID" DataType="System.Int32" ReadOnly="true" HeaderStyle-Width="6em" /> <telerik:GridBoundColumn DataField="COW_EID" HeaderText="Electronic ID" DataType="System.String" ReadOnly="true" HeaderStyle-Width="12em" /> <telerik:GridBoundColumn DataField="COW_LifeId" HeaderText="Birth ID" DataType="System.String" ReadOnly="true" HeaderStyle-Width="8em" /> <telerik:GridBoundColumn DataField="COW_VID" HeaderText="Current Visual ID" DataType="System.Int32" ReadOnly="true" HeaderStyle-Width="8em" /> <telerik:GridTemplateColumn DataField="COW_VID" HeaderText="New Visual ID" DataType="System.Int32" ReadOnly="false" HeaderStyle-Width="15em"> <EditItemTemplate> <telerik:RadNumericTextBox runat="server" ID="tbNewVisualID" SelectionOnFocus="SelectAll" AutoPostBack="false" MinValue="0" MaxValue="999999"> <NumberFormat DecimalDigits="0" GroupSeparator="" /> <ClientEvents OnKeyPress="TelerikVisualIDKeyPress" OnValueChanged="TelerikValueChanged" /> </telerik:RadNumericTextBox> <span class="errorText" style="display: none">*NOT UNIQUE*</span> </EditItemTemplate> </telerik:GridTemplateColumn> </Columns> </MasterTableView> </telerik:RadGrid></div>public partial class _Default : System.Web.UI.Page{ protected void Page_Load(object sender, EventArgs e) { } protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e) { var data = new List<object>(); for (int i = 0; i < 1000; i++) { data.Add(new {Cow_Id = i, Cow_EID = i,cow_LifeId = i, Cow_VID = i}); } TGrid.DataSource = data; } protected void RadGrid1_PreRender(object sender, EventArgs e) { foreach (GridItem item in TGrid.MasterTableView.Items) { if (item is GridEditableItem) { GridEditableItem editableItem = item as GridDataItem; editableItem.Edit = true; } } TGrid.Rebind(); }}editableItem.Edit = true; then changing the page size works as expected, but then the column is not editable. Any thoughts?@{
Html.Telerik().Grid(Model) .Name("Grid") .DataBinding(dataBinding => { dataBinding.Ajax() .Select("Select", "MyController") .Insert("Insert", "MyController") .Update("Update", "MyController") .Delete("Delete", "MyController"); }) .ClientEvents(events => events .OnDataBinding("onDataBinding") .OnComplete("onComplete") .OnEdit("onEdit") .OnRowDataBound("onRowDataBound")) .Columns(columns => { columns.Command(commands => { commands.Edit().ButtonType(GridButtonType.Image); commands.Delete().ButtonType(GridButtonType.Image); }).Width(30); ; columns.Bound(o => o.Id); columns.Bound(o => o.col1); .Aggregate(aggregates => aggregates.Sum()) .GroupFooterTemplate(@<text>@item.Sum</text>); columns.Bound(o => o.col2) .Aggregate(aggregates => aggregates.Sum()) .GroupFooterTemplate(@<text>@item.Sum</text>); columns.Bound(o => o.col3) .Aggregate(aggregates => aggregates.Sum()) .GroupFooterTemplate(@<text>@item.Sum</text>); }) .CellAction(cell => { if ((cell.Column.Member == "col1") { cell.HtmlAttributes["style"] = "background-color: red"; } }) .Sortable(sorting => sorting .SortMode(GridSortMode.MultipleColumn) ) .Filterable() .Render(); }
}