or
<telerik:RadTimePicker ID="radstarttime" runat="server" Width="225px" > <TimeView CellSpacing="-1" Columns="6" Interval="00:30:00" ></TimeView> </telerik:RadTimePicker> <asp:RequiredFieldValidator ID="rfvStartTime" Display="Dynamic" ValidationGroup="EditValidation" SetFocusOnError="true" runat="server" ControlToValidate="radstarttime" ErrorMessage="Start Time is Mandatory!!!" Text="*" ForeColor="Red"> </asp:RequiredFieldValidator> <telerik:RadTimePicker ID="radendtime" runat="server" Width="225px"> <TimeView CellSpacing="-1" Columns="6" Interval="00:30:00"></TimeView> </telerik:RadTimePicker> <asp:RequiredFieldValidator ID="rfvEndTime" Display="Dynamic" ValidationGroup="EditValidation" SetFocusOnError="true" runat="server" ControlToValidate="radendtime" ErrorMessage="End Time is Mandatory!!!" Text="*" ForeColor="Red"> </asp:RequiredFieldValidator> <asp:CompareValidator ID="crvEndTime" runat="server" ControlToCompare ="radstarttime" ControlToValidate ="radendtime" Operator ="GreaterThanEqual" ErrorMessage ="End Time Must be Greater than Start Time" > </asp:CompareValidator>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; }
}