Hi,
I have used a RadGrid inside a repeater, but having issues getting values out of it. Initially I realised I was rebinding on every postback, oops, but now changed that to only bind on initial load but when I click edit etc on the grid that particular GridView disappears.
I have used a RadGrid inside a repeater, but having issues getting values out of it. Initially I realised I was rebinding on every postback, oops, but now changed that to only bind on initial load but when I click edit etc on the grid that particular GridView disappears.
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="Config.ascx.cs" Inherits="Admin_Config" ClassName="Admin.Config" %>
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<
h1
>Config</
h1
>
<
script
type
=
"text/javascript"
>
function RowDblClick(sender, eventArgs) {
sender.get_masterTableView().editItem(eventArgs.get_itemIndexHierarchical());
}
</
script
>
<
asp:Repeater
ID
=
"rptGroups"
OnItemDataBound
=
"rptGroups_ItemDataBound"
runat
=
"server"
>
<
ItemTemplate
>
<
h2
><
asp:Literal
ID
=
"litHeader"
runat
=
"server"
/></
h2
>
<
asp:UpdatePanel
ID
=
"upKeys"
UpdateMode
=
"Conditional"
runat
=
"server"
>
<
ContentTemplate
>
<
asp:Literal
ID
=
"litTest"
runat
=
"server"
/>
<
telerik:RadGrid
ID
=
"rgKeys"
AutoGenerateColumns
=
"false"
AllowSorting
=
"True"
AutoGenerateEditColumn
=
"true"
AllowAutomaticUpdates
=
"True"
Skin
=
"Telerik"
OnUpdateCommand
=
"rgKeys_UpdateCommand"
runat
=
"server"
>
<
MasterTableView
EditMode
=
"PopUp"
CommandItemDisplay
=
"Bottom"
CommandItemSettings-AddNewRecordText
=
"Add new key"
CommandItemSettings-ShowRefreshButton
=
"false"
DataKeyNames
=
"name"
AllowSorting
=
"true"
>
<
Columns
>
<
telerik:GridBoundColumn
DataField
=
"Name"
HeaderText
=
"Name"
SortExpression
=
"Name"
UniqueName
=
"Name"
></
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"Alias"
HeaderText
=
"Alias"
SortExpression
=
"Alias"
UniqueName
=
"Alias"
></
telerik:GridBoundColumn
>
<
telerik:GridCheckBoxColumn
DataField
=
"Active"
HeaderText
=
"Active"
SortExpression
=
"Active"
UniqueName
=
"Active"
></
telerik:GridCheckBoxColumn
>
<
telerik:GridBoundColumn
DataField
=
"Value1"
HeaderText
=
"Value 1"
SortExpression
=
"Value1"
UniqueName
=
"Value1"
></
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"Value2"
HeaderText
=
"Value 2"
SortExpression
=
"Value2"
UniqueName
=
"Value2"
></
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"Value3"
HeaderText
=
"Value 3"
SortExpression
=
"Value3"
UniqueName
=
"Value3"
></
telerik:GridBoundColumn
>
</
Columns
>
<
EditItemStyle
ForeColor
=
"Gray"
></
EditItemStyle
>
<
EditFormSettings
InsertCaption
=
"Add new key"
CaptionFormatString
=
"Edit details key '{0}'"
CaptionDataField
=
"name"
PopUpSettings-Modal
=
"true"
>
<
FormCaptionStyle
Font-Bold
=
"true"
/>
</
EditFormSettings
>
</
MasterTableView
>
<
ClientSettings
>
<
ClientEvents
OnRowDblClick
=
"RowDblClick"
/>
</
ClientSettings
>
</
telerik:RadGrid
>
</
ContentTemplate
>
</
asp:UpdatePanel
>
</
ItemTemplate
>
</
asp:Repeater
>
using
System;
using
System.Collections;
using
System.Collections.Generic;
using
System.Linq;
using
System.Web;
using
System.Web.UI;
using
System.Web.UI.WebControls;
using
System.Xml;
using
System.Xml.Linq;
using
Telerik.Web.UI;
public
partial
class
Admin_Config : System.Web.UI.UserControl
{
protected
void
Page_Load(
object
sender, EventArgs e)
{
if
(!Page.IsPostBack)
{
XDocument Config = Cache.XDoc.Load(
"Config.xml"
);
rptGroups.DataSource = Config.Element(
"config"
).Elements(
"group"
).Where(x => x.Attribute(
"hidden"
).Value ==
"false"
);
rptGroups.DataBind();
}
}
protected
void
rptGroups_ItemDataBound(
object
sender, RepeaterItemEventArgs e)
{
XElement ConfigGroup = (XElement)e.Item.DataItem;
((Literal)e.Item.FindControl(
"litHeader"
)).Text = ConfigGroup.Attribute(
"alias"
).Value;
var Keys = from x
in
ConfigGroup.Elements(
"key"
)
where x.Attribute(
"hidden"
).Value ==
"false"
orderby Convert.ToInt32(x.Attribute(
"sortId"
).Value) ascending
select
new
{
Name = x.Attribute(
"name"
).Value,
Alias = x.Attribute(
"alias"
).Value,
Description = x.Attribute(
"description"
).Value,
Active = x.Attribute(
"active"
).Value,
SortId = x.Attribute(
"sortId"
).Value,
Value1 = x.Attribute(
"value1"
).Value,
Value2 = x.Attribute(
"value2"
).Value,
Value3 = x.Attribute(
"value3"
).Value
};
((RadGrid)e.Item.FindControl(
"rgKeys"
)).DataSource = Keys;
((RadGrid)e.Item.FindControl(
"rgKeys"
)).DataBind();
}
protected
void
rgKeys_UpdateCommand(
object
source, GridCommandEventArgs e)
{
Hashtable NewValues =
new
Hashtable();
e.Item.OwnerTableView.ExtractValuesFromItem(NewValues, (GridEditableItem)e.Item);
// Cant get any values out here...
}
}