Telerik Forums
UI for ASP.NET AJAX Forum
0 answers
61 views

Hello,
I have a graph containing several "LinesSeries". Each "LinesSeries" contains several points on the X axis but always the same value on Y (different value between the series)
I would like to know if it is possible to display the label of each serie only once and on the first point of each series.

thank you

Jérémy
Top achievements
Rank 1
 asked on 17 Jan 2018
0 answers
99 views

Hello, I am looking at this product to see if it can meet my needs.  What I have is an asp.net web form with C# code behind with 5 asp.net grid views on the page.  I have a lot of jquery and css customization including custom colors for the grid rows that I need an ability on an asp:button press event convert my grid to a pdf with the custom row colors.

 

Is this something your product can handle?  Do you have demo tutorial on how to do such?  I have looked but have not found it.

PinkSmelly
Top achievements
Rank 1
 asked on 17 Jan 2018
8 answers
1.0K+ views
I have the following set on my grid:
<MasterTableView> 
    <Columns> 
        <telerik:GridBoundColumn UniqueName="Description" DataField="Description" HtmlEncode="true" /> 
    </Columns> 
</MasterTableView> 

This properly escapes html entities that may exist in that field when using traditional data binding.

However when switching to the built-in code-less clientside databinding html values fail to get escaped. Eg
<ClientSettings> 
    <DataBinding Location="WebService.asmx" SelectMethod="GetData" /> 
</ClientSettings> 

This is a XSS security risk. Fix this.

Version is 2008.3.1314.35

Scott
Top achievements
Rank 1
 answered on 17 Jan 2018
9 answers
916 views
Story:
A user clicks on export to excel icon in the radgrid CommandItemTemplate section.

The user waits for some type of indication and does not see that IE is working so clicks again and etc...

We want a visible indicator to the user that the export is building and will soon download to their client machine...

Any ideas?
Marcus
Top achievements
Rank 1
 answered on 16 Jan 2018
3 answers
332 views

I'm using the telerik:RadSearchBox and have it connected to a datasource/web service with autocomplete enabled.

This datasource is connect to database table that has over 1 million records. On a page load or page preinit, the web page will timeout due to the large amount of data its trying to load.

What is the best method for the telerik:RadSearchBox to connect to the datasource and populate the autocomplete feature with a large dataset?

Thanks in advance.

Kevin

Peter Milchev
Telerik team
 answered on 16 Jan 2018
1 answer
170 views

I need to use drill down with drag and drop and integration with chart. i have used the samples to use drill down functionality. however, when i try to drag and drop one of the filterfield to row/column field. it shows the error to get correct count of rowfileld or columnfield. i tried to move code from on init to other places but it gives the error either way.

can you please help on this? 

<style>
    .breadcrumb {
    padding: 4px 10px !important;
    margin-bottom: 10px !important;
    list-style: none;
    background-color: #f5f5f5;
    border-radius: 4px;
}
</style>
  <telerik:RadCodeBlock runat="server">
        <style type="text/css">
            .rpgContentZone th[onclick],
            .rpgContentZone td[onclick]
            {
                cursor: pointer;
            }
        </style>
        <script type="text/javascript">
            function OpenDetailsWindow(argument)
            {
                $find("<%= RadAjaxPanel1.ClientID %>").ajaxRequest(argument);
            }
        </script>
    </telerik:RadCodeBlock>
<div>
        <!--start of breadcrumb-->
        <ol class="breadcrumb container">
            <li class="active">Incident Navigator</li>
            
            <li class="active">Trending</li>
        </ol>
 
     
 
     <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server">
        </telerik:RadAjaxLoadingPanel>
   <telerik:RadAjaxManagerProxy ID="AjaxManagerProxy1" runat="server">
        <AjaxSettings>
            <telerik:AjaxSetting AjaxControlID="RadPivotGrid1">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="RadPivotGrid1"  LoadingPanelID="RadAjaxLoadingPanel1" />
                     <telerik:AjaxUpdatedControl ControlID="RadHtmlChart1" LoadingPanelID="RadAjaxLoadingPanel1" />
                </UpdatedControls>
            </telerik:AjaxSetting>
            <telerik:AjaxSetting AjaxControlID="rdComboTicketType">
            <UpdatedControls>
                <telerik:AjaxUpdatedControl ControlID="RadPivotGrid1"  LoadingPanelID="RadAjaxLoadingPanel1" />
                     <telerik:AjaxUpdatedControl ControlID="RadHtmlChart1" LoadingPanelID="RadAjaxLoadingPanel1" />
 
            </UpdatedControls>
        </telerik:AjaxSetting>
        </AjaxSettings>
    </telerik:RadAjaxManagerProxy>
        
     
 <div class="container" style="padding: 0;">
     <div style="vertical-align:top;text-align:center;">
    <telerik:RadLabel runat="server" ID="lblReport" CssClass="reportlbl">
     
 
 
    </telerik:RadLabel>
          </div>
    <telerik:RadHtmlChart ID="RadHtmlChart1" Height="350px"  runat="server" Visible="true" Legend-Appearance-Position="Bottom"
         PlotArea-XAxis-LabelsAppearance-RotationAngle="45" PlotArea-YAxis-MinValue="0" PlotArea-YAxis-Type="Numeric">
       <%-- <ChartTitle >
                <Appearance Align="Center" BackgroundColor="Transparent" Position="Top">
                    <TextStyle FontSize="13" FontFamily="Helvetica Neue, Helvetica, Arial, sans-serif;" Bold="true" />
                </Appearance>
            </ChartTitle> --%>
    </telerik:RadHtmlChart>
     <br />
       <telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server" EnableAJAX="true" OnAjaxRequest="RadAjaxPanel1_AjaxRequest" LoadingPanelID="RadAjaxLoadingPanel1">
     <telerik:RadPivotGrid RenderMode="Lightweight" runat="server" ID="RadPivotGrid1"  AllowPaging="false"   OnCellDataBound="RadPivotGrid1_CellDataBound" OnNeedDataSource="RadPivotGrid1_NeedDataSource" OnDataBinding="RadPivotGrid1_DataBinding" OnItemCommand="RadPivotGrid1_ItemCommand"
            AllowSorting="true" AllowFiltering="true"  ShowFilterHeaderZone="true" EnableZoneContextMenu="true" >
        <%--    <PagerStyle Mode="NextPrevNumericAndAdvanced" AlwaysVisible="true"></PagerStyle>--%>
            <DataCellStyle Width="50px" />
            <Fields>
                 
                <telerik:PivotGridColumnField DataField="Year">
                </telerik:PivotGridColumnField>
                 <telerik:PivotGridReportFilterField DataField="Quarter"    >
                </telerik:PivotGridReportFilterField>
                  <telerik:PivotGridReportFilterField DataField="AffectedItemName" Caption="Application"   >
                </telerik:PivotGridReportFilterField>
                  <telerik:PivotGridReportFilterField DataField="WorkgroupName" Caption="Assignment group"    >
                </telerik:PivotGridReportFilterField>
                  <telerik:PivotGridReportFilterField DataField="Level"  Caption="Service Level"   >
                </telerik:PivotGridReportFilterField>
                  <telerik:PivotGridReportFilterField DataField="Severity"    >
                </telerik:PivotGridReportFilterField>
                <telerik:PivotGridColumnField DataField="MonthName"   SortOrder="None" >
                </telerik:PivotGridColumnField>
                <telerik:PivotGridRowField DataField="CauseCategoryName">
                </telerik:PivotGridRowField>
              <%--  <telerik:PivotGridRowField DataField="City">
                </telerik:PivotGridRowField>--%>
                <telerik:PivotGridAggregateField DataField="IncidentId" Aggregate="Count" SortOrder="Ascending" >
                </telerik:PivotGridAggregateField>
                 
             
            </Fields>
            
          <ClientSettings EnableFieldsDragDrop="true">
                <%--<Scrolling AllowVerticalScroll="true"></Scrolling>--%>
                 
         
                <ClientMessages DragToReorder="Drag the field to change its order"></ClientMessages>
            </ClientSettings>
        </telerik:RadPivotGrid>
 
 
             <telerik:RadWindow ID="RadWindow1" runat="server" MinWidth="900px" MinHeight="450px">
            <ContentTemplate>
                   <telerik:RadAjaxLoadingPanel runat="server" ID="RadAjaxLoadingPanel2" Skin="Default"></telerik:RadAjaxLoadingPanel>
                <telerik:RadAjaxPanel ID="RadAjaxPanel2" runat="server" LoadingPanelID="RadAjaxLoadingPanel2">
                    <telerik:RadGrid runat="server" ID="RadGrid1" AllowSorting="true" PageSize="5"
                        OnNeedDataSource="RadGrid1_NeedDataSource" AllowPaging="true">
                    </telerik:RadGrid>
                </telerik:RadAjaxPanel>
            </ContentTemplate>
        </telerik:RadWindow>
           </telerik:RadAjaxPanel>
 
 </div>
 
    <style type="text/css">
       .PivotGridWindow {
           width: 700px !important;
           height: 400px !important;
 
       }
        
       .reportlbl{
           font-size:small;
           font-family:Helvetica Neue, Helvetica, Arial, sans-serif;
           font-weight:bold;
                
       }
   </style>
   
     </div>
   -------------------------------
 public partial class TrendingControl : System.Web.UI.UserControl
    {
        List<PivotGridField> rowFields;
        List<PivotGridField> columnFields;
        List<PivotGridField> aggregateFields;
        int index = 0;
        int[] allFakeColumnCells = null;
        bool isFirstDataCell = true;
        int countOfFakeRowCells = 0;
        int cellsCount = 0;
        string firstRowID = string.Empty;
        string currentRowID = string.Empty;
        int key = 0;
 
 
    
        public int? AffectedItemId
        {
            get
            {
                if (((MasterPage)Page.Master).AppId != null)
                {
 
                    return ((MasterPage)Page.Master).AppId;
                }
                else
                {
                    return null;
                }
            }
        }
 
        public List<string> TicketTypelist
        {
 
            get
            {
                if (((MasterPage)Page.Master).TicketTypelist != null)
                {
 
                    return ((MasterPage)Page.Master).TicketTypelist;
                }
                else
                {
                    return null;
                }
            }
        }
 
        public Dictionary<int, string> Arguments
        {
            get
            {
                if (Session["Arguments"] == null)
                {
                    Session["Arguments"] = new Dictionary<int, string>();
                }
 
                return Session["Arguments"] as Dictionary<int, string>;
            }
            set
            {
                Session["Arguments"] = value;
            }
        }
 
        public DataTable GridDataSource
        {
            get
            {
                return Session["GridDataSource"] as DataTable;
            }
            set
            {
                Session["GridDataSource"] = value;
            }
        }
        
      
 
 
        public List<INAffectedItem> listAffectedItemlist
        {
            get
            {
                var list = new List<INAffectedItem>();
 
                using (var db = new Entities())
                {
                    list = db.INAffectedItems.ToList();
                }
 
                return list;
            }
        }
        HashSet<string> columnNames = new HashSet<string>();
        Dictionary<string, LineSeries> LineSeriesByRowName = new Dictionary<string, LineSeries>();
        protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);
            if (!Page.IsPostBack)
            {
                if (AffectedItemId == 0)
                {
                    using (var db = new Entities())
                    {
                        var v = db.IN_Trending_dS(string.Join(",", TicketTypelist));
                        string year = v.Max(x => x.Year).GetValueOrDefault().ToString();
                        RadPivotGrid1.FilterByLabel(PivotGridFilterFunction.Equals, RadPivotGrid1.Fields["Year"], year);
                        //RadPivotGrid1.FilterByValue(PivotGridFilterFunction.Top, RadPivotGrid1.Fields["AffectedItemName"], RadPivotGrid1.Fields["IncidentId"] as PivotGridAggregateField, "5");
                    }
 
                }
                else
                {
 
                    using (var db = new Entities())
                    {
                        var v = db.IN_TrendingByAffectedItem_dS(AffectedItemId.Value, string.Join(",", TicketTypelist));
                        var year = v.Max(x => x.Year).GetValueOrDefault().ToString();
                        RadPivotGrid1.FilterByLabel(PivotGridFilterFunction.Contains, RadPivotGrid1.Fields["Year"], year);
                    }
 
 
                }
            }
 
            //for (int i = 0; i < RadPivotGrid1.Fields.Count; i++)
            //{
            //    RadPivotGrid1.Fields[i].Caption = (i + 1).ToString();
            //}
            RadPivotGrid1.Fields["CauseCategoryName"].Caption = ClosureCategoryName;
 
            //RadPivotGrid1.ColumnGroupsDefaultExpanded = false;
            //RadPivotGrid1.RowGroupsDefaultExpanded = false;
            columnNames = new HashSet<string>();
            LineSeriesByRowName = new Dictionary<string, LineSeries>();
            RadPivotGrid1.Rebind();
 
 
        //    rowFields = RadPivotGrid1.Fields.Where(f =>
        //f is PivotGridRowField && f.IsHidden == false).OrderBy(f => f.ZoneIndex).ToList();
        //    columnFields = RadPivotGrid1.Fields.Where(f =>
        //         f is PivotGridColumnField && f.IsHidden == false).OrderBy(f => f.ZoneIndex).ToList();
        //    aggregateFields = RadPivotGrid1.Fields.Where(f =>
        //         f is PivotGridAggregateField && f.IsHidden == false).OrderBy(f => f.ZoneIndex).ToList();
        }
 
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            rowFields = RadPivotGrid1.Fields.Where(f =>
        f is PivotGridRowField && f.IsHidden == false).OrderBy(f => f.ZoneIndex).ToList();
            columnFields = RadPivotGrid1.Fields.Where(f =>
                 f is PivotGridColumnField && f.IsHidden == false).OrderBy(f => f.ZoneIndex).ToList();
            aggregateFields = RadPivotGrid1.Fields.Where(f =>
                 f is PivotGridAggregateField && f.IsHidden == false).OrderBy(f => f.ZoneIndex).ToList();
        }
        protected void Page_Load(object sender, EventArgs e)
        {
 
            if (AffectedItemId == 0)
            {
                lblReport.Text = "Monthly Incidents by " + ClosureCategoryName + " for All Applications";
            }
            else
            {
                var v = listAffectedItemlist.Where(x => x.Id == AffectedItemId.Value).FirstOrDefault();
                lblReport.Text = "Monthly Incidents by " + ClosureCategoryName + "  for " + v.AffectedItemName;
            }
 
 
            //this.RadHtmlChart1.PlotArea.XAxis.Items.Clear();
            //this.RadHtmlChart1.PlotArea.Series.Clear();
           // RadPivotGrid1.Rebind();
        }
 
        public static DataTable ToDataTable<T>(List<T> items)
        {
            DataTable dataTable = new DataTable(typeof(T).Name);
 
            //Get all the properties
            PropertyInfo[] Props = typeof(T).GetProperties(BindingFlags.Public | BindingFlags.Instance);
            foreach (PropertyInfo prop in Props)
            {
                //Defining type of data column gives proper data table
                var type = (prop.PropertyType.IsGenericType && prop.PropertyType.GetGenericTypeDefinition() == typeof(Nullable<>) ? Nullable.GetUnderlyingType(prop.PropertyType) : prop.PropertyType);
                //Setting column names as Property names
                dataTable.Columns.Add(prop.Name, type);
            }
            foreach (T item in items)
            {
                var values = new object[Props.Length];
                for (int i = 0; i < Props.Length; i++)
                {
                    //inserting property values to datatable rows
                    values[i] = Props[i].GetValue(item, null);
                }
                dataTable.Rows.Add(values);
            }
            //put a breakpoint here and check datatable
            return dataTable;
        }
 
 
        protected void RadPivotGrid1_NeedDataSource(object sender, Telerik.Web.UI.PivotGridNeedDataSourceEventArgs e)
        {
            if (AffectedItemId == 0)
            {
                using (var db = new Entities())
                {
                    var v = db.IN_Trending_dS(string.Join(",", TicketTypelist));
                    (sender as RadPivotGrid).DataSource = ToDataTable(v.OrderBy(x => x.Year).ThenBy(x => x.Month).ToList());
 
                }
 
 
            }
            else
            {
                using (var db = new Entities())
                {
                    var v = db.IN_TrendingByAffectedItem_dS(AffectedItemId.Value, string.Join(",", TicketTypelist));
                    if (v != null)
                    {
                        var selectedAppsource = v.OrderBy(x => x.Year).ThenBy(x => x.Month).ToList();
 
                        (sender as RadPivotGrid).DataSource = ToDataTable(selectedAppsource);
                    }
                }
 
            }
        }
 
        protected void RadPivotGrid1_CellDataBound(object sender, PivotGridCellDataBoundEventArgs e)
        {
            PivotGridDataCell cell = e.Cell as PivotGridDataCell;
 
            if (cell != null)
            {
                // If this is the first data cell we need to populate the collecion which fake columns cells count
                if (isFirstDataCell)
                {
                    PopulateFakeColumnsCellCollection(cell);
                    isFirstDataCell = false;
                }
                // We do not need to attach onclick event on cell which does not have values
                if (cell.DataItem != null)
                {
                    string argument = GetCommandArguments(cell);
                    string script = string.Format("OpenDetailsWindow('{0}')", argument);
                    cell.Attributes.Add("onclick", script);
                }
                index++;
            }
 
            PivotGridDataCell dataCell = e.Cell as PivotGridDataCell;
            if (columnNames.Count == 0)
            {
                this.RadHtmlChart1.PlotArea.XAxis.Items.Clear();
 
                this.RadHtmlChart1.PlotArea.Series.Clear();
                //if (AffectedItemId == 0)
                //{
                //    this.RadHtmlChart1.ChartTitle.Text = "Monthly Incidents by Closure Category for All Applications";
                //}
                //else
                //{
                //    var v = listIncidentlist.Where(x => x.AffectedItemId == AffectedItemId.Value).FirstOrDefault();
                //    this.RadHtmlChart1.ChartTitle.Text = "Monthly Incidents by Closure Category for " + v.AffectedItemName;
                //}
            }
 
            if (dataCell != null && dataCell.CellType == PivotGridDataCellType.DataCell)
            {
                string rowName = GetName(dataCell.ParentRowIndexes);
                //if(dataCell.ParentColumnIndexes[1]!= null)
                //{
                //    int month = 0;
                //    if (int.TryParse(dataCell.ParentColumnIndexes[1].ToString(), out month))
                //    {
                //        dataCell.ParentColumnIndexes[1]= CultureInfo.CurrentCulture.DateTimeFormat.GetAbbreviatedMonthName(int.Parse(dataCell.ParentColumnIndexes[1].ToString()));
                //    }
                //}
                string columnName = GetName(dataCell.ParentColumnIndexes);
                columnName = columnName.Replace('\'', ' ');
                if (columnNames.Add(columnName))
                {
                    AxisItem axisItem = new AxisItem(columnName);
                    this.RadHtmlChart1.PlotArea.XAxis.Items.Add(axisItem);
                }
                LineSeries lineSeries = null;
 
                if (LineSeriesByRowName.ContainsKey(rowName))
                {
                    lineSeries = LineSeriesByRowName[rowName];
                }
                else
                {
                    lineSeries = new LineSeries();
 
                    LineSeriesByRowName.Add(rowName, lineSeries);
                    lineSeries.Name = rowName;
                    // columnSeries.LabelsAppearance.DataFormatString = "C";
                    this.RadHtmlChart1.PlotArea.Series.Add(lineSeries);
                }
                lineSeries.LabelsAppearance.Visible = false;
                CategorySeriesItem item = new CategorySeriesItem();
                int value = 0;
                if (e.Cell.DataItem != null && int.TryParse(e.Cell.DataItem.ToString(), out value))
                {
                    item.Y = value;
                }
                else
                {
                    item.Y = null;
                }
                lineSeries.SeriesItems.Add(item);
            }
        }
 
        // This methos is executed only for the first cell from the first row
        private void PopulateFakeColumnsCellCollection(PivotGridDataCell cell)
        {
            PivotGridDataItem item = cell.NamingContainer as PivotGridDataItem;
            cellsCount = item.Cells.Count;
            allFakeColumnCells = new int[cellsCount];
            firstRowID = item.UniqueID;
 
            for (int i = 0; i < cellsCount; i++)
            {
                int countOfFakeCells = GetCountOfFakeColumnCells(item.Cells[i] as PivotGridDataCell);
                allFakeColumnCells[i] = countOfFakeCells;
            }
        }
        private string GetName(object[] indexes)
        {
            StringBuilder builder = new StringBuilder();
            foreach (object index in indexes)
            {
                builder.Append(index.ToString());
                builder.Append("/");
            }
            builder.Remove(builder.Length - 1, 1);
            return builder.ToString();
        }
 
        protected void RadPivotGrid1_DataBinding(object sender, EventArgs e)
        {
            Arguments.Clear();
        }
 
        protected void RadPivotGrid1_ItemCommand(object sender, PivotGridCommandEventArgs e)
        {
            RadWindow1.VisibleOnPageLoad = false;
        }
 
        protected void RadAjaxPanel1_AjaxRequest(object sender, AjaxRequestEventArgs e)
        {
            StringBuilder whereClause = new StringBuilder();
            if (!string.IsNullOrEmpty(e.Argument.ToString()))
            {
                string[] elements = e.Argument.ToString().Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                foreach (var element in elements)
                {
                    var group = element.Split(new char[] { '~' }, StringSplitOptions.RemoveEmptyEntries);
                    int firstPart = Convert.ToInt32(group[0]);
                    int secondPart = Convert.ToInt32(group[1]);
                    whereClause.Append(string.Format("{0} = '{1}' AND ", Arguments[firstPart], Arguments[secondPart]));
                }
 
                // Remove the last " AND " clause
                whereClause.Remove(whereClause.Length - 5, 5);
                GridDataSource = GetTable();
 
                //GridDataSource = GetDataTable(string.Format("SELECT * FROM Transportation WHERE {0}", whereClause.ToString()));
            }
            //Executed when row and column grandtotal cell is clicked
            else
            {
                GridDataSource = GetTable();
            }
 
            RadWindow1.VisibleOnPageLoad = true;
            RadGrid1.Rebind();
      
 
        }
        static DataTable GetTable()
        {
            // Here we create a DataTable with four columns.
            DataTable table = new DataTable();
            table.Columns.Add("Dosage", typeof(int));
            table.Columns.Add("Drug", typeof(string));
            table.Columns.Add("Patient", typeof(string));
            table.Columns.Add("Date", typeof(DateTime));
 
            // Here we add five DataRows.
            table.Rows.Add(25, "Indocin", "David", DateTime.Now);
            table.Rows.Add(50, "Enebrel", "Sam", DateTime.Now);
            table.Rows.Add(10, "Hydralazine", "Christoff", DateTime.Now);
            table.Rows.Add(21, "Combivent", "Janet", DateTime.Now);
            table.Rows.Add(100, "Dilantin", "Melanie", DateTime.Now);
            return table;
        }
 
        public string GetCommandArguments(PivotGridDataCell cell)
        {
            // True when first cell of each row is hit
            if (currentRowID != cell.NamingContainer.UniqueID)
            {
                index = 0;
                currentRowID = cell.NamingContainer.UniqueID;
                countOfFakeRowCells = GetCountOfFakeRowCells(cell);
            }
 
            object[] rowIndexes = cell.ParentRowIndexes;
            object[] columnIndexes = cell.ParentColumnIndexes;
 
            int rowIndexesCount = rowIndexes.Count();
            int columnIndexesCount = columnIndexes.Count();
 
            int countOfFakeColumnCells = allFakeColumnCells[index];
 
            rowIndexesCount -= countOfFakeRowCells;
            columnIndexesCount -= countOfFakeColumnCells;
 
            StringBuilder buider = BuildArguments(rowIndexes, columnIndexes, rowIndexesCount, columnIndexesCount);
 
            return buider.ToString();
        }
 
        private StringBuilder BuildArguments(object[] rowIndexes, object[] columnIndexes, int rowIndexesCount, int columnIndexesCount)
        {
            StringBuilder buider = new StringBuilder();
 
            ReplaceArgumentsWithNumbers(rowIndexes, rowFields, rowIndexesCount, buider);
            ReplaceArgumentsWithNumbers(columnIndexes, columnFields, columnIndexesCount, buider);
 
            // Remove the semicolon in the end
            if (buider.Length > 1)
            {
                buider.Remove(buider.Length - 1, 1);
            }
 
            return buider;
        }
 
        private void ReplaceArgumentsWithNumbers(object[] cellIndexes, List<PivotGridField> fields, int indexesCount, StringBuilder buider)
        {
            for (int i = 0; i < indexesCount; i++)
            {
                string firstPart = fields[i].DataField;
                string secondPart = cellIndexes[i].ToString();
                if (Arguments.ContainsValue(firstPart))
                {
                    buider.Append(Arguments.FirstOrDefault(a => a.Value == firstPart).Key);
                    AppendSecondParts(buider, secondPart);
                }
                else
                {
                    Arguments.Add(key, firstPart);
                    buider.Append(string.Format("{0}", key.ToString()));
                    key++;
                    AppendSecondParts(buider, secondPart);
                }
            }
        }
 
        private void AppendSecondParts(StringBuilder buider, string secondPart)
        {
            if (Arguments.ContainsValue(secondPart))
            {
                buider.Append(string.Format("~{0};", Arguments.FirstOrDefault(a => a.Value == secondPart).Key));
            }
            else
            {
                Arguments.Add(key, secondPart);
                buider.Append(string.Format("~{0};", key.ToString()));
                key++;
            }
        }
 
        private int GetCountOfFakeColumnCells(PivotGridDataCell cell)
        {
            int count = 0;
            if (aggregateFields.Count > 1)
            {
                if (RadPivotGrid1.AggregatesPosition == PivotGridAxis.Columns)
                {
                    if (cell.CellType == PivotGridDataCellType.DataCell ||
                        cell.CellType == PivotGridDataCellType.RowTotalDataCell ||
                        cell.CellType == PivotGridDataCellType.RowAndColumnTotal ||
                        cell.CellType == PivotGridDataCellType.RowGrandTotalDataCell ||
                        cell.CellType == PivotGridDataCellType.ColumnGrandTotalRowTotal)
                    {
                        count++;
                    }
                }
            }
 
            // if column total or grand total cell is hit we need to escape its values from query
            if (cell.CellType == PivotGridDataCellType.ColumnTotalDataCell ||
                cell.CellType == PivotGridDataCellType.RowAndColumnTotal ||
                cell.CellType == PivotGridDataCellType.ColumnGrandTotalRowTotal ||
                cell.CellType == PivotGridDataCellType.ColumnGrandTotalDataCell ||
                cell.CellType == PivotGridDataCellType.RowGrandTotalColumnTotal)
            {
                count++;
            }
 
            return count;
        }
 
        private int GetCountOfFakeRowCells(PivotGridDataCell cell)
        {
            int count = 0;
            //if aggregates are more than one additional cells are rendered, so we need to exclude their values from the query
            if (aggregateFields.Count > 1)
            {
                if (RadPivotGrid1.AggregatesPosition == PivotGridAxis.Rows)
                {
                    if (cell.CellType != PivotGridDataCellType.RowTotalDataCell &&
                        cell.CellType != PivotGridDataCellType.ColumnGrandTotalRowTotal)
                    {
                        count++;
                    }
                }
            }
 
            // if row total or grand total cell is hit we need to escape its values from query
            if (cell.CellType == PivotGridDataCellType.RowTotalDataCell ||
                cell.CellType == PivotGridDataCellType.ColumnGrandTotalRowTotal ||
                cell.CellType == PivotGridDataCellType.RowGrandTotalDataCell)
            {
                count++;
            }
 
            return count;
        }
 
        protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
        {
            RadGrid1.DataSource = GridDataSource;
        }
 
    }
}
James
Top achievements
Rank 1
 answered on 16 Jan 2018
2 answers
97 views

Hello,

for our website i've built some functionality into our basepage that creates a commandrow with a 'ClearAllFilters' button for every grid.

At first glance this seems to work fine. However, when selecting an item in a grid after a postback (for example filtering, or paging) it is selecting not from the filtered source, but the unfiltered source. So visually the grid is filtered, but when selecting an item it is using the complete list.

 

Somehow i have the feeling that the adding of a handler for the itemcommand is overwriting certain functionality that is otherwise called during the itemcommand event. However i have not been able to fix the problem, and ive tried tons of things.

Please have a look at the code and let me know if i am doing something wrong here!

 

Public Class BasePage
        Inherits Page
 
        Private ReadOnly Property AllowedFilterItems As String() = New String() {"Contains", "StartsWith", "EqualTo", "NotEqualTo"}
 
        Protected Overrides Sub OnInit(e As EventArgs)
            For Each grid As RadGrid In Controls.All().OfType(Of RadGrid)()
                DefineGridStructure(grid)
            Next
            MyBase.OnInit(e)
        End Sub
 
        Private Sub DefineGridStructure(grid As RadGrid)
            AddHandler grid.Load, New EventHandler(AddressOf Grid_OnLoad)
            AddHandler grid.ItemCommand, New GridCommandEventHandler(AddressOf Grid_OnCommand)
            AddHandler grid.PreRender, New EventHandler(AddressOf Grid_OnPreRender)
            AddCommandRow(grid)
        End Sub
 
        Protected Sub BasePage_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
            SetupRadgridPaging()
        End Sub
 
#Region "Radgrid event handlers and helper functions"
        Public Sub SetupRadgridPaging()
            For Each grid As RadGrid In Controls.All().OfType(Of RadGrid)()
                If grid.MasterTableView.DetailTables.Count = 0 AndAlso (grid.AllowPaging OrElse grid.MasterTableView.AllowPaging) Then
                    AddHandler grid.PageSizeChanged, AddressOf Grid_OnPageSizeChanged
                    Dim pageSize = GetPagerSizeForUser(GetGridPagerSettingsKey(grid.ID))
 
                    UpdateNewPageSize = False
                    grid.PageSize = pageSize
 
                    grid.PagerStyle.AlwaysVisible = True
                    grid.AllowPaging = False
 
                    grid.MasterTableView.PageSize = pageSize
                    grid.MasterTableView.PagerStyle.AlwaysVisible = True
                    grid.MasterTableView.AllowPaging = True
 
                    UpdateNewPageSize = True
                End If
            Next
        End Sub
 
        Private Sub Grid_OnCommand(sender As Object, e As GridCommandEventArgs)
            Dim grid As RadGrid = CType(sender, RadGrid)
            If e.CommandName.Equals("ClearAllFilters", StringComparison.InvariantCultureIgnoreCase) Then
                For Each column As GridColumn In grid.Columns
                    column.CurrentFilterFunction = GridKnownFunction.NoFilter
                    column.CurrentFilterValue = String.Empty
                Next
 
                grid.MasterTableView.FilterExpression = String.Empty
                grid.Rebind()
            End If
        End Sub
 
        Private Sub Grid_OnLoad(sender As Object, e As EventArgs)
            Dim grid As RadGrid = CType(sender, RadGrid)
            ConfigureFilterMenu(grid)
        End Sub
 
        Private Sub Grid_OnPreRender(sender As Object, e As EventArgs)
            Dim grid As RadGrid = CType(sender, RadGrid)
            SetCommandItemVisibility(grid)
        End Sub
 
        Private Sub SetCommandItemVisibility(grid As RadGrid)
            Dim hasFilter As Boolean = False
            For Each column As GridColumn In grid.Columns
                If Not column.CurrentFilterValue = String.Empty Then
                    hasFilter = True
                    Exit For
                End If
            Next
 
            grid.MasterTableView.CommandItemDisplay = If(hasFilter, GridCommandItemDisplay.Top, GridCommandItemDisplay.None)
            grid.Rebind()
        End Sub
 
        Private Sub AddCommandRow(grid As RadGrid)
            grid.MasterTableView.CommandItemTemplate = New GridCommandItemTemplate(CType(LocalizationManager, LocalizationManager))
        End Sub
 
        Private Sub ConfigureFilterMenu(grid As RadGrid)
            grid.FilterMenu.Items().ToList().ForEach(Sub(fi) grid.FilterMenu.Items.Remove(fi))
            AllowedFilterItems.ForEach(Sub(fi) grid.FilterMenu.Items.Add(New RadMenuItem(fi) With {.Value = fi}))
            grid.FilterMenu.Localize(App.Session.CurrentCultureIdentifier)
        End Sub
 
        Public Sub Grid_OnPageSizeChanged(sender As Object, e As GridPageSizeChangedEventArgs)
            Dim grid As RadGrid = CType(sender, RadGrid)
            UpdateUserSetting(GetGridPagerSettingsKey(grid.ID), e.NewPageSize.ToString())
        End Sub
 
        Public Function GetGridPagerSettingsKey(grid As String) As String
            Const prefix As String = "CPGridPager"
            Dim sPath As String = Request.Url.AbsolutePath
            Dim oInfo As New FileInfo(sPath)
            Dim pageName As String = Path.GetFileNameWithoutExtension(oInfo.Name)
            Return String.Concat(prefix, separator, pageName, separator, grid)
        End Function
 
#Region "GridCommandItemTemplate"
        Private Class GridCommandItemTemplate
            Implements ITemplate
 
            Private clearFilter As ImageButton
            Private _localizationManager As LocalizationManager
 
            Public Sub New(ByRef localizationManager As LocalizationManager)
                MyBase.New
                _localizationManager = localizationManager
            End Sub
 
            Public Sub InstantiateIn(container As Control) Implements ITemplate.InstantiateIn
                clearFilter = New ImageButton With {
                    .ID = "clearFilter",
                    .ToolTip = _localizationManager.Localize("Grid_ClearFilters", App.Session.CurrentCultureIdentifier),
                    .CommandName = "ClearAllFilters",
                    .ImageUrl = "/Images/Grid/ClearFilter.png"
                }
 
                container.Controls.Add(clearFilter)
            End Sub
        End Class
#End Region
#End Region
Johan
Top achievements
Rank 1
 answered on 16 Jan 2018
5 answers
1.2K+ views
Simple grid populated on the page load from a data table

loads fine

but if you then select any of the paging controls to move to another page it disappears

please see the following video


the page is within a master page which has this code in it

    <telerik:RadScriptManager ID="RadScriptManager1" runat="server"
        <Scripts> 
            <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js" /> 
            <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQuery.js" /> 
        </Scripts> 
    </telerik:RadScriptManager>  


Then within the page itself its like this:

                    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server"
                        <ajaxsettings> 
                            <telerik:AjaxSetting AjaxControlID="RadGridGroups"
                                <UpdatedControls> 
                                    <telerik:AjaxUpdatedControl ControlID="RadGridGroups" /> 
                                </UpdatedControls> 
                            </telerik:AjaxSetting> 
                        </ajaxsettings> 
                    </telerik:RadAjaxManager> 
                    <strong>Groups:</strong> 
                    <telerik:RadGrid ID="RadGridGroups" runat="server" AllowPaging="true" 
                        PageSize="5" GridLines="None" width="95%"
                        <clientsettings allowkeyboardnavigation="true" enablepostbackonrowclick="true"
                            <Selecting AllowRowSelect="true" /> 
                        </clientsettings> 
                        <mastertableview datakeynames="Group_ID" /> 
                        <pagerstyle mode="NextPrevAndNumeric" /> 
                    </telerik:RadGrid> 


Any ideas what its doing or I am missing or doing wrong?

Thanks

Jon.
Darius
Top achievements
Rank 1
 answered on 16 Jan 2018
5 answers
776 views
Hi
We want to upgrade to the latest version of Rad controls.
Currently we are using the following controls with respective versions in our application.
    RadAjax.Net2.dll      1.7.2.0 
    RadCalendar.Net2.dll  2.1.2.0 
    RadComboBox.Net2.dll  2.7.2.0 
    RadGrid.Net2.dll     4.6.2.0 
    RadWindow.Net2.dll   1.8.2.0 
    RadTabStrip.Net2.dll 3.5.2.0 
    RadSplitter.Net2.dll 1.2.2.1 
    RadMenu.Net2.dll     4.3.2.0 
    RadInput.Net2.dll    2.0.2.0 
    RadWindow.Net2.dll  1.8.2.0

From Teleric site we came to know that to upgrade to the latest version we will have to manually change the code files to make use of latest version. See below link.

We are looking for some way by which we can upgrade to the latest version by just changing the Dll reference or any other quick way.

Please advice.

regards,
Sandeep



Rumen
Telerik team
 answered on 16 Jan 2018
4 answers
1.0K+ views
I am getting the error "Selection out of range Parameter name: value". I have a radcombobox inside a FormTemplate in the radgrid.
Find the code for reference.

<telerik:RadGrid AutoGenerateColumns="False" ID="rgModel" Skin="WebBlue"  
        AllowPaging="True" runat="server" OnItemDataBound="rgModel_ItemDataBound">
        <PagerStyle Mode="NextPrevAndNumeric" />                            
        <MasterTableView DataKeyNames="ModelId" CommandItemDisplay="Top" CommandItemSettings-ShowRefreshButton="false">
            <Columns>      
                    <telerik:GridEditCommandColumn  UniqueName="EditCommandColumn1" ButtonType="ImageButton" >
                    <HeaderStyle Width="20px" />                                                                                                                                               
                    <ItemStyle CssClass="MyImageButton" />
                </telerik:GridEditCommandColumn>                                                       
                <telerik:GridBoundColumn HeaderText="Manufacturer" DataField="Manufacturer"
                    UniqueName="Manufacturer" HeaderStyle-HorizontalAlign="left" />
                <telerik:GridButtonColumn CommandName="Delete" Text="Delete" UniqueName="DeleteColumn" ConfirmText="Do You want to delete the Manufacturer?">
                </telerik:GridButtonColumn>                          
            </Columns>
            <EditFormSettings EditFormType="Template">
                <FormTemplate>                   
                    <table id="Table3" cellspacing="1" cellpadding="1" width="500" border="0" class="module">                                                                                                                                                                                                                  
                        <tr>
                            <td>Manufacturer:</td>
                            <td>
                                <telerik:RadComboBox ID="ddlManufacturer" AppendDataBoundItems="true" runat="server" Skin="WebBlue"                                                          
                                    SelectedValue='<%# Bind("ManufacturerId")%>'>                                                           
                                </telerik:RadComboBox
                            </td>
                        </tr>                                                                                                  
                        <tr>
                            <td> </td>
                            <td>
                                    <asp:Button ID="btnUpdate" Text='<%# IIf((TypeOf(Container) is GridEditFormInsertItem), "Insert", "Update") %>'
                                    runat="server" CommandName='<%# IIf((TypeOf(Container) is GridEditFormInsertItem), "PerformInsert", "Update")%>'>
                                </asp:Button
                                <asp:Button ID="btnCancel" Text="Cancel" runat="server" CausesValidation="False"
                                CommandName="Cancel"></asp:Button>
                            </td>
                        </tr>
                    </table>                                      
                </FormTemplate>
            </EditFormSettings>                    
        </MasterTableView>
    </telerik:RadGrid>           
  
Protected Sub rgModel_ItemDataBound(ByVal source As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs)
        Dim blnReturn As Boolean
        Dim strErrMsg As String = String.Empty
        Dim interrno As Integer
        Dim dtbManufacturer As New DataTable
        
  
        If (TypeOf e.Item Is GridEditableItem AndAlso e.Item.IsInEditMode) Then
  
            Dim ddlManufacturer As Telerik.Web.UI.RadComboBox = e.Item.FindControl("ddlManufacturer")
            
            blnReturn = _objW.GetManufacturers(dtbManufacturer)
  
            If Equals(blnReturn, True) Then
    ddlManufacturer.Items.Clear()
    ddlManufacturer.SelectedValue = Nothing
                ddlManufacturer.DataSource = dtbManufacturer
                ddlManufacturer.DataTextField = dtbManufacturer.Columns(1).ColumnName
                ddlManufacturer.DataValueField = dtbManufacturer.Columns(0).ColumnName
                ddlManufacturer.DataBind()
            End If
        End If
    End Sub
Leidi
Top achievements
Rank 1
 answered on 15 Jan 2018
Narrow your results
Selected tags
Tags
+? more
Top users last month
Rob
Top achievements
Rank 3
Iron
Iron
Iron
Atul
Top achievements
Rank 1
Iron
Iron
Iron
Alexander
Top achievements
Rank 1
Veteran
Iron
Serkan
Top achievements
Rank 1
Iron
Shawn
Top achievements
Rank 1
Iron
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
Rob
Top achievements
Rank 3
Iron
Iron
Iron
Atul
Top achievements
Rank 1
Iron
Iron
Iron
Alexander
Top achievements
Rank 1
Veteran
Iron
Serkan
Top achievements
Rank 1
Iron
Shawn
Top achievements
Rank 1
Iron
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?