Consider the following grid ...
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 ...
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
<
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
>
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">
<
html
xmlns
=
"http://www.w3.org/1999/xhtml"
>
<
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