This is a migrated thread and some comments may be shown as answers.

Default value Grid

3 Answers 101 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jean-Yves
Top achievements
Rank 1
Jean-Yves asked on 06 Dec 2010, 04:47 PM
Hello all, 

I would like to ask you a question. In a website, usualy, you keep the same environement in the all solution.
So, when I put a <telerik:RadGrid, I would like to set default value only once in the project. Do you know if its possible ?

Like : 
<telerik:RadGrid    
 
        GridLines="None" PageSize="20" AutoGenerateColumns="false" Culture="fr-FR"
        EnableHeaderContextMenu="true" EnableHeaderContextFilterMenu="true" AllowFilteringByColumn="true"
        AllowPaging="True" AllowSorting="True" ShowFooter="True"
         
    AllowAutomaticUpdates="True" AllowAutomaticDeletes="True">
 
     
    <HeaderContextMenu EnableImageSprites="True" CssClass="GridContextMenu GridContextMenu_Default" />
         
    <MasterTableView ShowGroupFooter="true" IsFilterItemExpanded="false">
 
        <Columns>
                <telerik:GridEditCommandColumn ButtonType="ImageButton" EditText="Editer" CancelText="Annuler" UpdateText="Mettre à jour" InsertText="Ajouter" />
         
 
 
            <telerik:GridButtonColumn CommandName="Delete" ButtonType="ImageButton" Text="Supprimer" />
        </Columns>
            <EditFormSettings>
                    <EditColumn ButtonType="ImageButton" EditText="Editer" CancelText="Annuler" UpdateText="Mettre à jour" InsertText="Ajouter" />
            </EditFormSettings>
 
    </MasterTableView>
 
</telerik:RadGrid>


Thank you very much

Jean-Yves
PageSize="20" AutoGenerateColumns="false" Culture="fr-FR"
            EnableHeaderContextMenu="true" EnableHeaderContextFilterMenu="true" AllowFilteringByColumn="true"
            AllowPaging="True" AllowSorting="True" ShowFooter="True"
PageSize="20" AutoGenerateColumns="false" Culture="fr-FR"
            EnableHeaderContextMenu="true" EnableHeaderContextFilterMenu="true" AllowFilteringByColumn="true"
            AllowPaging="True" AllowSorting="True" ShowFooter="True"
GridLines="None" PageSize="20" AutoGenerateColumns="false" Culture="fr-FR"
            EnableHeaderContextMenu="true" EnableHeaderContextFilterMenu="true" AllowFilteringByColumn="true"
            AllowPaging="True" AllowSorting="True" ShowFooter="True"
PageSize="20" AutoGenerateColumns="false" Culture="fr-FR"
            EnableHeaderContextMenu="true" EnableHeaderContextFilterMenu="true" AllowFilteringByColumn="true"
            AllowPaging="True" AllowSorting="True" ShowFooter="True"

3 Answers, 1 is accepted

Sort by
0
Vasil
Telerik team
answered on 08 Dec 2010, 02:41 PM
Hi Jean-Yves,

You can make your own web user control which contains RadGrid. Then use this user control in all your pages.

The following links can be helpful:
http://www.beansoftware.com/ASP.NET-Tutorials/User-Control.aspx
http://msdn.microsoft.com/en-us/library/fb3w5b53.aspx

Regards,
Vasil
the Telerik team
Browse the vast support resources we have to jumpstart your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
Jean-Yves
Top achievements
Rank 1
answered on 15 Apr 2011, 07:51 PM
Hello, 

I know it's an old post... But I would like to know a bit more :)
In fact, all the grids will be différent... Just the page size will be the same... and it's just to not repeat the pagesize.

If I put a Grid in a user control I will not be able to use all the properties directely, or I'm missing something.

I tried something like this : 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Telerik.Web.UI;
 
namespace ISI.Web.Common.Util
{
    public class RadGridiSi : RadGrid
    {
        //protected override void OnLoad(EventArgs e)
        //{
        //    PageSize = 20;
        //    base.OnLoad(e);
        //}
        protected override void OnInit(EventArgs e)
        {
            PageSize = 20;
            base.OnInit(e);
        }
 
        //protected override void OnPreRender(EventArgs e)
        //{
        //    PageSize = 20;
        //    base.OnPreRender(e);
        //}
    }
}
 but it's not a real sucess...


In fact I just want to set the defaults properties of a grid... But, if I want to customise only one... I can...

I think that it's possible... I hope so :p

Thank you

Jean-Yves
0
Vasil
Telerik team
answered on 20 Apr 2011, 04:04 PM
Hello Jean-Yves,

You are on the right track. You can define the default values in the constructor of your class.

For example let's define our custom grid and inherit the RadGrid. Our grid will have PageSize 7 by default and also will have sample default NeedDataSource handler.

namespace MyControls
{
    public class MyRadGrid : RadGrid
    {
        public MyRadGrid()
            : base()
        {
            this.PageSize = 7;
            this.AllowPaging = true;
            this.NeedDataSource += new GridNeedDataSourceEventHandler(MyRadGrid_NeedDataSource);
        }
 
        void MyRadGrid_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
        {
            this.DataSource = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
        }
    }
}

Now let's use it in simple page:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="UsingMyControls.aspx.cs"
  Inherits="UsingMyControls" %>
 
<%@ Register TagPrefix="MyControls" Namespace="MyControls" %>
<body>
  <form id="form1" runat="server">
  <asp:ScriptManager runat="server">
    <script runat="server" type="text/C#">
      protected void MyRadGrid2_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
      {
        MyRadGrid2.DataSource = new string[] { "a", "s", "d", "f", "g", "h", "j", "k" };
      }
    </script>
  </asp:ScriptManager>
  <MyControls:MyRadGrid ID="MyRadGrid1" runat="server" PageSize=" 8">
    <%-- will have page size 8 and the data will be 1 2 3 4 5 6 7 8 9 10 --%>
  </MyControls:MyRadGrid>
  <MyControls:MyRadGrid ID="MyRadGrid2" runat="server" OnNeedDataSource="MyRadGrid2_NeedDataSource">
    <%-- will have page size 7 and the data will be a s d f g h j k--%>
  </MyControls:MyRadGrid>
  </form>
</body>
</html>

As you can see, the first grid will have page size 8 (that we set in the declaration). And the second will have the custom DataSource and the default page size 7.

You can also check this help topic for more information:
http://www.telerik.com/help/aspnet-ajax/grdinheritance.html

Kind regards,
Vasil
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

Tags
Grid
Asked by
Jean-Yves
Top achievements
Rank 1
Answers by
Vasil
Telerik team
Jean-Yves
Top achievements
Rank 1
Share this question
or