Hello,
i want to display a button and the group header text at a GridGroupHeader cell. After some searching and trying I found some usefull code snippets but the behavior is not as expected. After the PostBack-Event the group header text disappears and only the button is shown.
In a prior test i moved the logic to the PreRender event, but the event registration for the radButton does not work in this case.
Can you please point me to the right direction.
thanks and greetings
Uwe
i want to display a button and the group header text at a GridGroupHeader cell. After some searching and trying I found some usefull code snippets but the behavior is not as expected. After the PostBack-Event the group header text disappears and only the button is shown.
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Grid.aspx.cs" Inherits="GridTest.ForecastGridTest" %>
<%@ 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"
>
<
title
></
title
>
</
head
>
<
body
>
<
form
id
=
"form1"
runat
=
"server"
>
<
telerik:RadStyleSheetManager
ID
=
"RadStyleSheetManager1"
runat
=
"server"
>
</
telerik:RadStyleSheetManager
>
<
telerik:RadScriptManager
ID
=
"RadScriptManager1"
runat
=
"server"
>
</
telerik:RadScriptManager
>
<
div
>
<
telerik:RadGrid
ID
=
"RadGrid1"
runat
=
"server"
AllowPaging
=
"True"
AutoGenerateColumns
=
"false"
CellSpacing
=
"0"
GridLines
=
"None"
ShowGroupPanel
=
"True"
OnNeedDataSource
=
"RadGrid1_OnNeedDataSource"
OnItemDataBound
=
"RadGrid1_OnItemDataBound"
OnItemCreated
=
"RadGrid1_OnItemCreated"
>
<
ClientSettings
AllowDragToGroup
=
"True"
>
</
ClientSettings
>
<
MasterTableView
AutoGenerateColumns
=
"False"
GroupLoadMode
=
"Server"
GroupsDefaultExpanded
=
"False"
>
<
GroupByExpressions
>
<
telerik:GridGroupByExpression
>
<
SelectFields
><
telerik:GridGroupByField
FieldName
=
"gl1"
HeaderText
=
"gl1"
/></
SelectFields
>
<
GroupByFields
><
telerik:GridGroupByField
FieldName
=
"gl1"
SortOrder
=
"Ascending"
/></
GroupByFields
>
</
telerik:GridGroupByExpression
>
<
telerik:GridGroupByExpression
>
<
SelectFields
><
telerik:GridGroupByField
FieldName
=
"gl2"
HeaderText
=
"gl2"
/></
SelectFields
>
<
GroupByFields
><
telerik:GridGroupByField
FieldName
=
"gl2"
SortOrder
=
"Ascending"
/></
GroupByFields
>
</
telerik:GridGroupByExpression
>
</
GroupByExpressions
>
<
Columns
>
<
telerik:GridTemplateColumn
HeaderStyle-Width
=
"100px"
>
<
ItemTemplate
>
<
telerik:RadButton
ID
=
"RadButton1"
runat
=
"server"
OnClick
=
"OnClick"
ButtonType
=
"LinkButton"
Text
=
"plah"
CommandName
=
""
></
telerik:RadButton
>
<
telerik:RadButton
ID
=
"RadButton2"
runat
=
"server"
OnClick
=
"OnClick"
ButtonType
=
"LinkButton"
Text
=
"plah"
></
telerik:RadButton
>
</
ItemTemplate
>
</
telerik:GridTemplateColumn
>
<
telerik:GridButtonColumn
HeaderText
=
"Status"
UniqueName
=
"ImageColumn"
ButtonType
=
"ImageButton"
HeaderStyle-Width
=
"100px"
/>
<
telerik:GridBoundColumn
DataField
=
"Forecast_Id"
DataType
=
"System.String"
FilterControlAltText
=
"Filter type1 column"
HeaderText
=
"ForecastId"
UniqueName
=
"Forecast"
/>
<
telerik:GridBoundColumn
Display
=
"False"
DataField
=
"Forecast_StdInt03"
DataType
=
"System.Int32"
UniqueName
=
"Status"
/>
</
Columns
>
<
CommandItemSettings
ExportToPdfText
=
"Export to PDF"
></
CommandItemSettings
>
<
RowIndicatorColumn
FilterControlAltText
=
"Filter RowIndicator column"
>
<
HeaderStyle
Width
=
"20px"
></
HeaderStyle
>
</
RowIndicatorColumn
>
<
ExpandCollapseColumn
FilterControlAltText
=
"Filter ExpandColumn column"
>
<
HeaderStyle
Width
=
"20px"
></
HeaderStyle
>
</
ExpandCollapseColumn
>
<
EditFormSettings
>
<
EditColumn
FilterControlAltText
=
"Filter EditCommandColumn column"
></
EditColumn
>
</
EditFormSettings
>
</
MasterTableView
>
<
FilterMenu
EnableImageSprites
=
"False"
></
FilterMenu
>
<
HeaderContextMenu
CssClass
=
"GridContextMenu GridContextMenu_Default"
></
HeaderContextMenu
>
</
telerik:RadGrid
>
</
div
>
<
telerik:RadAjaxManager
runat
=
"server"
>
</
telerik:RadAjaxManager
>
<
asp:ObjectDataSource
runat
=
"server"
ID
=
"osd1"
TypeName
=
"GridTest.DataAccess"
SelectMethod
=
"GetDataTable"
>
</
asp:ObjectDataSource
>
</
form
>
</
body
>
</
html
>
using
System;
using
System.Collections.Generic;
using
System.Data;
using
System.Drawing;
using
System.Linq;
using
System.Web;
using
System.Web.UI;
using
System.Web.UI.WebControls;
using
Telerik.Web.UI;
namespace
GridTest
{
public
partial
class
ForecastGridTest : System.Web.UI.Page
{
protected
void
Page_Load(
object
sender, EventArgs e)
{
RadGrid1.MasterTableView.HierarchyDefaultExpanded =
false
;
}
protected
void
RadGrid1_OnNeedDataSource(
object
sender, GridNeedDataSourceEventArgs e)
{
var dataAccess =
new
DataAccess();
var dataTable = dataAccess.GetDataTable();
if
(sender
is
RadGrid)
{
var grid = sender
as
RadGrid;
grid.DataSource = dataTable;
}
}
protected
void
OnClick(
object
sender, EventArgs e)
{
if
(sender
is
RadButton)
{
var button = sender
as
RadButton;
button.ForeColor = Color.Red;
}
}
protected
void
RadGrid1_OnItemDataBound(
object
sender, GridItemEventArgs e)
{
_AppendButtonToHeader(e.Item);
}
protected
void
RadGrid1_OnItemCreated(
object
sender, GridItemEventArgs e)
{
_AppendButtonToHeader(e.Item);
}
private
void
_AppendButtonToHeader(
object
item)
{
if
(item
is
GridGroupHeaderItem)
{
var gridGroupHeaderItem = item
as
GridGroupHeaderItem;
var dataCell = gridGroupHeaderItem.DataCell;
var radButton =
new
RadButton();
radButton.ButtonType = RadButtonType.StandardButton;
radButton.Text =
"do"
;
radButton.Click +=
new
EventHandler(radButton_Click);
dataCell.Controls.Add(radButton);
dataCell.Controls.Add(
new
LiteralControl(dataCell.Text));
}
}
void
radButton_Click(
object
sender, EventArgs e)
{
}
}
}
In a prior test i moved the logic to the PreRender event, but the event registration for the radButton does not work in this case.
Can you please point me to the right direction.
thanks and greetings
Uwe