or
We have a diamically created radgrid with lots checkbox column in it. They all display fine. But I have problem for looping through it and get it's value. It seems can't find the checkbox control on the page. Not sure where I missed.
foreach (Functions function in CurrentUserFunctionList)
{
// Set up the RadGrid's columns
// NOTE: We have to use a custom TemplateColumn, because each checkbox is its own unique control, with its own unique ID.
GridTemplateColumn gtcFunction = new GridTemplateColumn();
gtcFunction.HeaderText = function.Description;
gtcFunction.DataField = function.FunctionId.ToString();
gtcFunction.ReadOnly = false;
gtcFunction.AllowFiltering = false;
// NOTE: The FunctionId gets passed in because it's part of each checkbox control's ID...
gtcFunction.ItemTemplate = new RadGridCheckBoxTemplate(function.FunctionId.ToString());
rgWeb.MasterTableView.Columns.Add(gtcFunction);
// Set up the Data Table's columns
DataColumn thiscolumn = new DataColumn();
thiscolumn.Caption = function.Description;
thiscolumn.ColumnName = function.FunctionId.ToString();
thiscolumn.ReadOnly = false;
thiscolumn.DataType = System.Type.GetType("System.Boolean");
MyDataTable.Columns.Add(thiscolumn);
}
}
public class RadGridCheckBoxTemplate : System.Web.UI.ITemplate
{
private string colname;
/// <
summary
>
/// This class sets up a Template with dynamically named CheckBoxes in the RadGrid. cName is the unique identifier for th column,
/// which is added to the ID of each CheckBox control.
/// </
summary
>
/// <
param
name
=
"type"
></
param
>
public RadGridCheckBoxTemplate(string cName)
{
this.colname = cName;
}
/// <
summary
>
/// Create the template
/// </
summary
>
/// <
param
name
=
"container"
></
param
>
public void InstantiateIn(System.Web.UI.Control container)
{
CheckBox checkbox = new CheckBox();
//checkbox.AutoPostBack = true;
checkbox.DataBinding += new EventHandler(boolValue_DataBinding);
checkbox.ID = "cbox_" + colname;
checkbox.CheckedChanged += new EventHandler(ToggleRowSelection);
container.Controls.Add(checkbox);
}
void boolValue_DataBinding(object sender, EventArgs e)
{
CheckBox cBox = (CheckBox)sender;
GridDataItem container = (GridDataItem)cBox.NamingContainer;
cBox.Checked = (bool)((DataRowView)container.DataItem)[colname];
}
/// <
summary
>
/// Check and uncheck
/// </
summary
>
/// <
param
name
=
"sender"
></
param
>
/// <
param
name
=
"e"
></
param
>
void ToggleRowSelection(object sender, EventArgs e)
{
((sender as CheckBox).Parent.Parent as GridItem).Selected = (sender as CheckBox).Checked;
}
}
foreach (Control ctrl in Page.Controls)
{
if (ctrl is CheckBox)
{
string a = ctrl.ID;// never comes here to show the control id
}
}
<
telerik:GridTemplateColumn
HeaderText
=
"User"
UniqueName
=
"User"
Reorderable
=
"false"
Display
=
"true"
SortExpression
=
"User"
>
<
ItemTemplate
>
<
asp:LinkButton
ID
=
"btnButton1"
runat
=
"server"
ToolTip
=
"Edit this user"
CommandName
=
"EditUser"
Visible="<%# Master.UserPrefs.HasEditRights %>"><%# Eval("User") %></
asp:LinkButton
>
<
asp:Label
ID
=
"lblLabel1"
runat
=
"server"
Visible="<%#!Master.UserPrefs.HasEditRights %>"><%# Eval("User") %></
asp:Label
>
</
ItemTemplate
>
</
telerik:GridTemplateColumn
>
protected void gvUsers_ItemCommand(object sender, GridCommandEventArgs e)
{
RadGrid grid = (RadGrid)sender;
switch (e.CommandName.ToUpper())
{
case "MyCommandName":
foreach (GridDataItem item in grid.MasterTableView.Items)
{
string cellContent = ((GridLinkButton)item.Cells[3].Controls[0]).Text
}
break;
}
}
|
M
|
XL |
XXL |
|||
T-Shirts |
Qty |
Amount |
Qty |
Amount |
Qty |
Amount |
Nike |
1 |
300 |
|
|
2 |
4 |
Reebok |
|
|
1 |
3 |
|
|
Smash |
2 |
145 |
|
|
2 |
3 |
foreach (RadListBoxItem item in RadListBox1.Items)
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ 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
>
<
link
href
=
"css/StyleSheet.css"
rel
=
"stylesheet"
type
=
"text/css"
/>
<
script
src
=
"js/jquery-1.5_1.js"
type
=
"text/javascript"
></
script
>
<
script
src
=
"js/behaviours.js"
type
=
"text/javascript"
></
script
>
</
head
>
<
body
>
<
form
id
=
"form1"
runat
=
"server"
>
<
div
>
<
telerik:RadScriptManager
ID
=
"RadScriptManager1"
runat
=
"server"
>
</
telerik:RadScriptManager
>
<
telerik:RadAjaxManager
ID
=
"RadAjaxManager1"
runat
=
"server"
>
<
ClientEvents
OnRequestStart
=
"jsAjaxStarting"
OnResponseEnd
=
"ajaxFinished"
/>
<
AjaxSettings
>
<
telerik:AjaxSetting
AjaxControlID
=
"Button1"
>
<
UpdatedControls
>
<
telerik:AjaxUpdatedControl
ControlID
=
"Panel1"
/>
</
UpdatedControls
>
</
telerik:AjaxSetting
>
<
telerik:AjaxSetting
AjaxControlID
=
"Button2"
>
<
UpdatedControls
>
<
telerik:AjaxUpdatedControl
ControlID
=
"Panel2"
/>
<
telerik:AjaxUpdatedControl
ControlID
=
"tab1IsAJAX"
/>
</
UpdatedControls
>
</
telerik:AjaxSetting
>
</
AjaxSettings
>
</
telerik:RadAjaxManager
>
<
div
id
=
"loadingDiv"
class
=
"screenCenter"
style
=
"display: none;"
>
<
br
/>
<
br
/>
<
span
>LOADING</
span
>
</
div
>
<
telerik:RadTabStrip
ID
=
"TestRadTabStrip"
runat
=
"server"
OnClientLoad
=
"jsStoreLicenceApplicTabStripClientObject"
SelectedIndex
=
"0"
MultiPageID
=
"RadMultiPage1"
>
<
Tabs
>
<
telerik:RadTab
PageViewID
=
"RadPageView1"
runat
=
"server"
Text
=
"Tab 1"
Value
=
"Tab1"
></
telerik:RadTab
>
<
telerik:RadTab
PageViewID
=
"RadPageView2"
runat
=
"server"
Text
=
"Tab 2"
Value
=
"Tab2"
></
telerik:RadTab
>
</
Tabs
>
</
telerik:RadTabStrip
>
<
telerik:RadMultiPage
ID
=
"RadMultiPage1"
runat
=
"server"
SelectedIndex
=
"0"
>
<
telerik:RadPageView
ID
=
"RadPageView1"
runat
=
"server"
>
<
asp:Panel
ID
=
"Panel2"
runat
=
"server"
>
<
p
>This is page 1</
p
>
</
asp:Panel
>
<
asp:Button
ID
=
"Button1"
runat
=
"server"
Text
=
"Go to Tab 2"
OnClick
=
"Click1"
/><
br
/>
<
asp:Label
ID
=
"tab1IsAJAX"
Text
=
""
runat
=
"server"
/>
</
telerik:RadPageView
>
<
telerik:RadPageView
ID
=
"RadPageView2"
runat
=
"server"
>
<
asp:Panel
ID
=
"Panel1"
runat
=
"server"
>
<
p
>This is page 2</
p
>
<
asp:Button
ID
=
"Button2"
runat
=
"server"
Text
=
"Go to Tab 1"
OnClick
=
"Click2"
/><
br
/>
<
asp:Label
ID
=
"tab2IsAJAX"
Text
=
""
runat
=
"server"
/>
</
asp:Panel
>
<
asp:Button
ID
=
"Button3"
runat
=
"server"
Text
=
"Hide Panel"
/><
br
/>
</
telerik:RadPageView
>
</
telerik:RadMultiPage
>
<
telerik:RadCodeBlock
ID
=
"RadCodeBlock1"
runat
=
"server"
>
<
script
type
=
"text/javascript"
>
$(document).ready(hookUpEvents);
function hookUpEvents() {
var tabId = '<%= TestRadTabStrip.ClientID %>';
var tabStrip = $find(tabId);
debugger;
if (tabStrip) {
var selectedTab = tabStrip.get_selectedTab();
var tabvalue = selectedTab.get_value();
}
if (tabvalue === 'Tab2')
$('#' + '<%= RadPageView2.FindControl("Panel1").ClientID %>').bind('click', hidePanel);
}
</
script
>
</
telerik:RadCodeBlock
>
</
div
>
</
form
>
</
body
>
</
html
>