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

ClientSelectColumn

2 Answers 91 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Stuart Hemming
Top achievements
Rank 2
Stuart Hemming asked on 08 Sep 2010, 12:43 PM
Consider the following grid ...
<telerik:RadGrid ID="RadGrid1"
                 runat="server"
                 AutoGenerateColumns="false"
                 AllowMultiRowSelection="false">
    <MasterTableView>
        <Columns>
            <telerik:GridClientSelectColumn UniqueName="Select"
                                            Visible="true"></telerik:GridClientSelectColumn>
            <telerik:GridBoundColumn UniqueName="Name"
                                     DataField="Name"
                                     HeaderText="Name"></telerik:GridBoundColumn>
            <telerik:GridBoundColumn UniqueName="Email"
                                     DataField="Email"
                                     HeaderText="Email"></telerik:GridBoundColumn>
        </Columns>
    </MasterTableView>
    <ClientSettings>
        <Selecting AllowRowSelect="true"/>
    </ClientSettings>
</telerik:RadGrid>
Running the page with this definition on it displays a grid with a select column. The select column's header has a checkbox in it. This is all good.

Now, consider the case where the above grid should only display the select column under programmer-defined conditions. Also consider that the grid should be limited to single row selection when the select column is not visible.

The following code sets up an example for this ...
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default5.aspx.cs" Inherits="Default5" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1"
              runat="server">
            <telerik:RadScriptManager ID="RadScriptManager1"
                                      runat="server">
            </telerik:RadScriptManager>
            <telerik:RadGrid ID="RadGrid1"
                             runat="server"
                             AutoGenerateColumns="false"
                             AllowMultiRowSelection="false">
                <MasterTableView>
                    <Columns>
                        <telerik:GridClientSelectColumn UniqueName="Select"
                                                        Visible="true"></telerik:GridClientSelectColumn>
                        <telerik:GridBoundColumn UniqueName="Name"
                                                 DataField="Name"
                                                 HeaderText="Name"></telerik:GridBoundColumn>
                        <telerik:GridBoundColumn UniqueName="Email"
                                                 DataField="Email"
                                                 HeaderText="Email"></telerik:GridBoundColumn>
                    </Columns>
                </MasterTableView>
                <ClientSettings>
                    <Selecting AllowRowSelect="true"/>
                </ClientSettings>
            </telerik:RadGrid>
            <asp:Button ID="Button1"
                        runat="server"
                        Text="Click"
                        OnClick="Button1_Click"/>
        </form>
    </body>
</html>
using System.Collections.Generic;
using System;
 
public class Contact
{
    public string Email { get; set; }
 
    public string Name { get; set; }
}
 
public partial class Default5 : System.Web.UI.Page
{
    protected void Button1_Click(object sender, EventArgs e)
    {
        bool currentValue = RadGrid1.Columns.FindByUniqueName("Select").Visible;
        RadGrid1.AllowMultiRowSelection = !currentValue;
        RadGrid1.Columns.FindByUniqueName("Select").Visible = !currentValue;
    }
 
    protected void Page_Load(object sender, EventArgs e)
    {
        List<Contact> contacts = new List<Contact>{
            new Contact{Name = "Stuart Hemming1", Email = "sejhemming@gmail.com"},
            new Contact{Name = "Stuart Hemming2", Email = "sejhemming2@gmail.com"},
            new Contact{Name = "Stuart Hemming3", Email = "sejhemming3@gmail.com"},
            new Contact{Name = "Stuart Hemming4", Email = "sejhemming4@gmail.com"},
            new Contact{Name = "Stuart Hemming5", Email = "sejhemming2@gmail.com"},
            new Contact{Name = "Stuart Hemming6", Email = "sejhemming@gmail.com"}
        };
        RadGrid1.DataSource = contacts;
        RadGrid1.DataBind();
    }
}

Run the page and you have a grid with 2 columns and a single button. Click the button to display the select column and to allow multirow selection. When the grid redraws, it does so with the select column displayed but no checkbox appears in the header.

Is this broken, or am I just missing something?

-- 
Stuart

2 Answers, 1 is accepted

Sort by
0
Accepted
Dimo
Telerik team
answered on 08 Sep 2010, 12:55 PM
Hello Stuart,

Please rebind the RadGrid control after making the changes in the button click handler.

Best wishes,
Dimo
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Stuart Hemming
Top achievements
Rank 2
answered on 08 Sep 2010, 12:59 PM
> > Is this broken, or am I just missing something?
Please rebind the RadGrid control after making the changes in the button click handler.
So, unsurprisingly, it's answer B (again!) :-)

Thanks Dimo,

-- 
Stuart
Tags
Grid
Asked by
Stuart Hemming
Top achievements
Rank 2
Answers by
Dimo
Telerik team
Stuart Hemming
Top achievements
Rank 2
Share this question
or