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

RadGrid and Skins

6 Answers 143 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Suzi
Top achievements
Rank 1
Suzi asked on 05 Jan 2009, 11:08 AM
Hi, I have an RadGrid into my page which contains a column named "Comment" :

 

<telerik:RadGrid ID="RadGridOrderLines" SkinId="MyRadGrid"

 

 

runat="server">

 

 

<MasterTableView Width="100%">

 

 

<Columns>

 

 

 

<telerik:GridTemplateColumn HeaderText="Comment" ItemStyle-HorizontalAlign="Left">

 

 

<HeaderTemplate>

 

 

Comment

 

 

</HeaderTemplate>

 

 

<ItemTemplate>

 

 

<asp:Label runat="server" id="lblComment2"></asp:Label>

 

 

</ItemTemplate>

 

 

<EditItemTemplate>

 

 

<asp:TextBox runat="server" id="tbComment2" Text='' TextMode="MultiLine" Rows="4" Columns="20"></asp:TextBox>

 

 

</EditItemTemplate>

 

 

</telerik:GridTemplateColumn>

 

 

 

</Columns>

 

 

</MasterTableView>

 

 

</telerik:RadGrid>

I use a skin named MyRadGrid which contains a several columns (TechnicalReference,...) : 

 

<

 

telerik:RadGrid SkinID="MyRadGrid" runat="server"

 

 

Skin="Default"

 

 

 

 

 

AlternatingItemStyle-BackColor="#EAF3F7"

 

 

EnableEmbeddedSkins="false"

 

 

datakeynames="OrderLineId" Width="98%"

 

 

AutoGenerateColumns="false">

 

 

 

 

 

<MasterTableView Width="100%">

 

 

<Columns>

 

 

 

 

 

<telerik:GridTemplateColumn HeaderText="Reference" ItemStyle-HorizontalAlign="Left">

 

 

 

 

 

<HeaderTemplate>

 

 

TechnicalReference

 

 

 

 

 

</HeaderTemplate>

 

 

 

 

 

<ItemTemplate>

 

 

 

 

 

<asp:HiddenField runat="server" id="hidOrderLineId" Value=''></asp:HiddenField>

 

 

 

 

 

<asp:Label runat="server" id="lblReference" Text=''></asp:Label>

 

 

 

 

 

</ItemTemplate>

 

 

 

 

 

</telerik:GridTemplateColumn>
....

My problem is that when I display the page, I see the columns Comment and TechnicalReference. I don't understand why I don't see only the column of the Skin (TechnicalReference).  When, I test with the GridView control of Asp.net, it displays only the columns of the skin (TechnicalReference).  Why is it different ?

I use the RadGrid control into all my pages, and I really need that it have the same behaviour of the GridView. 

Do you have an idea to resolve my problem easily ?

Thank you in advance,

Suzi.

 

 

6 Answers, 1 is accepted

Sort by
0
Dimo
Telerik team
answered on 08 Jan 2009, 01:18 PM
Hi Suzi,

The observed behavior in RadGrid is expected and the reason is that the RadGrid control has a different sctructure from the GridView. However, there is a workaround - you can check whether there are columns added from an ASP.NET theme, and if yes, make the other columns invisible:

ASPX

<%@ Page Language="C#" Theme="theme182794" %> 
<%@ Import Namespace="System.Data" %> 
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %> 
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
 
<html xmlns="http://www.w3.org/1999/xhtml"
<head runat="server"
<meta http-equiv="content-type" content="text/html; charset=utf-8" /> 
<title>RadControls for ASP.NET AJAX</title> 
</head> 
<body> 
<form id="form1" runat="server"
<asp:ScriptManager ID="ScriptManager1" runat="server" /> 
 
<telerik:RadGrid 
    ID="RadGrid1" 
    runat="server" 
    AllowSorting="true" 
    AutoGenerateColumns="false" 
    OnNeedDataSource="RadGrid_NeedDataSource"
    <MasterTableView> 
        <Columns> 
            <telerik:GridBoundColumn DataField="Column1" HeaderText="Column 1 ASPX" /> 
            <telerik:GridBoundColumn DataField="Column2" HeaderText="Column 2 ASPX" /> 
        </Columns> 
    </MasterTableView> 
</telerik:RadGrid> 
 
<asp:GridView 
    ID="GridView1" 
    runat="server" 
    AutoGenerateColumns="false"
    <Columns> 
        <asp:BoundField DataField="Column1" HeaderText="Column 1 ASPX" /> 
        <asp:BoundField DataField="Column2" HeaderText="Column 2 ASPX" /> 
    </Columns> 
</asp:GridView> 
 
</form> 
</body> 
</html> 


C#

    protected int ThemeColumns; 
     
    protected override void OnPreInit(EventArgs e) 
    { 
        base.OnPreInit(e); 
        ThemeColumns = RadGrid1.Columns.Count; 
    } 
 
    protected override void OnInit(EventArgs e) 
    { 
        base.OnInit(e); 
        if (ThemeColumns > 0) 
        { 
            for (int j = 0; j < RadGrid1.Columns.Count - ThemeColumns; j++) 
            { 
                RadGrid1.Columns[j].Visible = false
            } 
        } 
    } 
     
    protected void RadGrid_NeedDataSource(object sender, GridNeedDataSourceEventArgs e) 
    { 
        (sender as RadGrid).DataSource = GetDataSource(); 
    } 
 
    protected void Page_Load(object sender, EventArgs e) 
    { 
        if (!IsPostBack) 
        { 
            GridView1.DataSource = GetDataSource(); 
            GridView1.DataBind(); 
        } 
    } 
     
    protected DataTable GetDataSource() 
    { 
        DataTable dt = new DataTable(); 
        DataRow dr; 
        int colsNum = 4; 
        int rowsNum = 10; 
        string colName = "Column"
 
        for (int j = 1; j <= colsNum; j++) 
        { 
            dt.Columns.Add(String.Format("{0}{1}", colName, j)); 
        } 
 
        for (int i = 1; i <= rowsNum; i++) 
        { 
            dr = dt.NewRow(); 
 
            for (int k = 1; k <= colsNum; k++) 
            { 
                dr[String.Format("{0}{1}", colName, k)] = String.Format("{0}{1} Row{2}", colName, k, i); 
            } 
            dt.Rows.Add(dr); 
        } 
 
        return dt; 
    } 
 


SKIN

<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %> 
 
<telerik:RadGrid runat="server"
    <MasterTableView> 
        <Columns> 
            <telerik:GridBoundColumn DataField="Column3" HeaderText="Column 3 Theme" /> 
            <telerik:GridBoundColumn DataField="Column4" HeaderText="Column 4 Theme" /> 
        </Columns> 
    </MasterTableView> 
</telerik:RadGrid> 
 
<asp:GridView runat="server"
    <Columns> 
        <asp:BoundField DataField="Column3" HeaderText="Column 3 Theme" /> 
        <asp:BoundField DataField="Column4" HeaderText="Column 4 Theme" /> 
    </Columns> 
</asp:GridView> 



Sincerely yours,
Dimo
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Suzi
Top achievements
Rank 1
answered on 04 Feb 2009, 02:52 PM
Ok, I will do like that. Thank you very much for your help !
0
Suzi
Top achievements
Rank 1
answered on 06 Feb 2009, 08:49 AM
I am testing this solution. It is a very good idea, thank you, but strangely, it doesn't work. The RadGrid is always null into the method OnPreInit. I don't know why ?

 

protected override void OnPreInit(EventArgs e)

 

{

 

base.OnPreInit(e);

 

 

if(RadGrid!=null)

 

ThemeColumns = RadGrid.Columns.Count;

 

}

Do you have an idea ? Is it working for you ?

Thank you in advance,

0
Dimo
Telerik team
answered on 06 Feb 2009, 09:05 AM
Hello Suzi,

Yes, the solution works on my side as expected.

Try using an ID for RadGrid, which is different from the control's name:

ThemeColumns = RadGrid1.Columns.Count;

Of course, in order to be available in PreInit, the RadGrid control must be added declaratively on the page.


Greetings,
Dimo
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Suzi
Top achievements
Rank 1
answered on 06 Feb 2009, 10:55 AM
I am sorry, it works very well with your example, but it doesn't work into my project. I am using a theme into the web.config.

I found an other solution which work into my project. I use the property VirtualItemCount :

<

 

telerik:RadGrid SkinID="MailDivGrid" runat="server"

 

 

 

datakeynames="OrderLineId" Width="98%"

 

 

 

AutoGenerateColumns="false">

 

 

 

<mastertableview VirtualItemCount="1">

 

 

 

<rowindicatorcolumn>

 

 

 

<HeaderStyle Width="20px" />

 

 

 

</rowindicatorcolumn>

 

 

 

<expandcollapsecolumn>

 

 

 

<HeaderStyle Width="20px" />

 

 

 

</expandcollapsecolumn>

 

 

 

<Columns>

 

 

 

<telerik:GridTemplateColumn HeaderText="MailDivCode" ItemStyle-HorizontalAlign="Left">

 

 

 

 

 

 

<ItemTemplate>

 

 

<asp:Label runat="server" id="lblCode" Text='<%# Bind("Code") %>'></asp:Label>

 

 

 

</ItemTemplate>

 

 

 

</telerik:GridTemplateColumn>

 

 

 

 

</Columns>

 

 

 

</mastertableview>

 

 

</

 

telerik:RadGrid>

 

 



 

protected override void OnInit(EventArgs e)

 

{

 

 

 

 

 

base.OnInit(e);

 

 

int themeColumns = 0;

 

themeColumns = RadGridMailDivs.MasterTableView.VirtualItemCount;

 

 

if (themeColumns > 0)

 

{

 

 

for (int j = 0; j < RadGridMailDivs.Columns.Count - themeColumns; j++) {

 

RadGridMailDivs.Columns[j].Visible =

 

false;

 

}

}

}

The property VirtualItemCount can be use for that ?

 

0
Dimo
Telerik team
answered on 06 Feb 2009, 02:28 PM
Hi Suzi,

I am afraid that the VirtualItemCount property is not related to the number of columns in the ASP.NET theme. You cannot use that.

Please review carefully my example once again and try to find out what should be changed in your implementation.

If you need further advice, please open a new support ticket and send us a simple runnable project, so that we can see what's happening.

All the best,
Dimo
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Grid
Asked by
Suzi
Top achievements
Rank 1
Answers by
Dimo
Telerik team
Suzi
Top achievements
Rank 1
Share this question
or