<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" > <AjaxSettings> <telerik:AjaxSetting AjaxControlID="myTimer"> <UpdatedControls> <telerik:AjaxUpdatedControl ControlID="label1" UpdatePanelRenderMode="Inline" /> </UpdatedControls> </telerik:AjaxSetting> </AjaxSettings></telerik:RadAjaxManager>protected void myTimer_Tick(object sender, EventArgs e){ label1.Text = "ABC"; titrePage.Text = "DEF";}<head runat="server"> <title id="titrePage" runat="server"></title></head><telerik:RadGrid ID="TransporterAssignmentGrid" runat="server" OnItemCreated="TransporterAssignmentGrid_ItemCreated" OnItemDataBound="TransporterAssignmentGrid_ItemDataBound" OnNeedDataSource="TransporterAssignmentGrid_NeedDataSource" Width="99%" AutoGenerateColumns="false"> <ClientSettings> <Selecting AllowRowSelect="true" /> </ClientSettings> <MasterTableView DataKeyNames="TransporterId"> </MasterTableView> </telerik:RadGrid>
Then in the Page_Init event there is a call to the "CreateTransporterAssignmentGridColumns" operation whose code contains the follwing:
// Create the GridClientSelectColumn (checkbox/row-selection)... GridClientSelectColumn gridClientSelectColumn = new GridClientSelectColumn(); gridClientSelectColumn.UniqueName = "GridClientSelectColumn"; gridClientSelectColumn.HeaderStyle.Width = System.Web.UI.WebControls.Unit.Pixel(25); gridClientSelectColumn.ItemStyle.Width = System.Web.UI.WebControls.Unit.Pixel(25);
this.TransporterAssignmentGrid.MasterTableView.Columns.Add ( gridClientSelectColumn );
// Create the TransporterId bound column... GridBoundColumn transporterIdGridBoundColumn = new GridBoundColumn(); transporterIdGridBoundColumn.UniqueName = "TransporterIdColumn"; transporterIdGridBoundColumn.DataField = "TransporterId"; transporterIdGridBoundColumn.DataType = typeof(Int32); transporterIdGridBoundColumn.ReadOnly = true; transporterIdGridBoundColumn.HeaderText = "Transporter ID"; transporterIdGridBoundColumn.HeaderStyle.Width = System.Web.UI.WebControls.Unit.Pixel(125); transporterIdGridBoundColumn.ItemStyle.Width = System.Web.UI.WebControls.Unit.Pixel(125);
this.TransporterAssignmentGrid.MasterTableView.Columns.Add ( transporterIdGridBoundColumn );
// Create the TransporterName bound column... GridBoundColumn transporterNameGridBoundColumn = new GridBoundColumn(); transporterNameGridBoundColumn.UniqueName = "TransporterNameColumn"; transporterNameGridBoundColumn.DataField = "TransporterName"; // Handled in ItemDataBound... transporterNameGridBoundColumn.DataType = typeof(Int32); transporterNameGridBoundColumn.ReadOnly = true; transporterNameGridBoundColumn.HeaderText = "Transporter Name"; transporterNameGridBoundColumn.HeaderStyle.Width = System.Web.UI.WebControls.Unit.Pixel(350); transporterNameGridBoundColumn.ItemStyle.Width = System.Web.UI.WebControls.Unit.Pixel(350);
this.TransporterAssignmentGrid.MasterTableView.Columns.Add ( transporterNameGridBoundColumn );
// Create a column for each UnitCategory foreach (UnitCategory unitCategory in ZoneMaintenancePage.UnitCategoryList) { GridTemplateColumn gridTemplateColumn = new GridTemplateColumn(); gridTemplateColumn.UniqueName = unitCategory.Name + "Column"; gridTemplateColumn.HeaderText = unitCategory.Name; gridTemplateColumn.HeaderStyle.Width = System.Web.UI.WebControls.Unit.Pixel(100); gridTemplateColumn.ItemStyle.Width = System.Web.UI.WebControls.Unit.Pixel(100); gridTemplateColumn.ItemTemplate = new UnitCategoryColumnTemplate ( this.Page, unitCategory.Name );
this.TransporterAssignmentGrid.MasterTableView.Columns.Add ( gridTemplateColumn ); } The template for the Unit Category column contains a single CheckBox control...
/// <summary> /// /// </summary> private class UnitCategoryColumnTemplate : ITemplate { #region Constructor
/// <summary> /// /// </summary> /// <param name="columnName"></param> public UnitCategoryColumnTemplate ( Page parentPage, string unitCategtoryName ) { this.ParentPage = parentPage; this.UnitCategoryName = unitCategtoryName; }
#endregion
#region Properties
/// <summary> /// /// </summary> public Page ParentPage { get; set; }
/// <summary> /// /// </summary> public string UnitCategoryName { get; set; }
#endregion
// Control Events
#region UnitCategoryCheckBox_CheckedChanged /// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public void UnitCategoryCheckBox_CheckedChanged(object sender, EventArgs e) { object x = sender as CheckBox; }
#endregion
// ITemplate Operations
#region InstantiateIn
/// <summary> /// /// </summary> /// <param name="container"></param> public void InstantiateIn(System.Web.UI.Control container) { try { // Determine the Transporter ID... GridDataItem gridDataItem = container.NamingContainer as GridDataItem;
int transporterId = Convert.ToInt32 ( gridDataItem.GetDataKeyValue("TransporterId") );
CheckBox checkBox = new CheckBox(); checkBox.ID = "Transporter" + transporterId + "_" + UnitCategoryName + "CheckBox"; checkBox.AutoPostBack = true;
checkBox.CheckedChanged += new EventHandler ( UnitCategoryCheckBox_CheckedChanged );
container.Controls.Add ( checkBox ); } catch { throw; } }
#endregion }
The item being used for the DataSource is a very simple List<T> object where the list item is a simple object with just the TransporterId property so that the grid can use that value for a DataKey... All the data binding is handled in the ItemDataBound event by using that TransporterId and other data sources...
protected void TransporterAssignmentGrid_ItemDataBound(object sender, GridItemEventArgs e) { if (e.Item is GridDataItem) { GridDataItem gridDataItem = e.Item as GridDataItem;
// Reference the TransporterId from the data-binding object... int transporterId = Convert.ToInt32 ( gridDataItem.GetDataKeyValue("TransporterId") );
// Reference the Transporter for the current TransporterId... Transporter transporter = ZoneMaintenancePage.TransporterList.FindByTransporterId ( transporterId );
// Reference the ZoneTransporterAssignment entries for the current Transporter... TransporterZoneAssignmentList transporterZoneAssignmentList = ZoneMaintenancePage.TransporterZoneAssignmentList.FindByTransporterId ( transporterId );
// Populate the Transporter ID/Name columns... gridDataItem.Cells[gridDataItem.GetIndexOfColumn("TransporterIdColumn")].Text = transporter.Id.ToString(); gridDataItem.Cells[gridDataItem.GetIndexOfColumn("TransporterNameColumn")].Text = transporter.Name;
// Populate the Unit Category columns... foreach (UnitCategory unitCategory in ZoneMaintenancePage.UnitCategoryList) { // Reference the entry for this Unit Category (should be 1 record only if any)... TransporterZoneAssignmentList unitCategoryTransporterZoneAssignmentList = transporterZoneAssignmentList.FindByUnitCategoryId ( unitCategory.UnitCategoryId );
// Reference & populate the CheckBox for the appropriate GridCheckBoxColumn... CheckBox checkBox = gridDataItem.Cells[gridDataItem.GetIndexOfColumn(unitCategory.Name + "Column")].Controls[0] as CheckBox; checkBox.Checked = (unitCategoryTransporterZoneAssignmentList.Count > 0); } } }
The problem I am having is being able to use the CheckBox controls' CheckedChanged event... I can not get this Event to fire properly... I have an event wired-up in the Template control class itself and have used it to set a breakpoint and test - but I never hit my breakpoint...
Additionally,
[A] I've tried adding the EventHandler during the Grid's ItemDataBound event...
[B] I've tried adding the EventHandler during the Grid's ItemCreated event...
[C] I've tried adding RadScriptManager.GetCurrent(ParentPage).RegisterAsyncPostBackControl(checkBox) in the Template (before adding to the Controls collection)...
[D] I've tried adding RadScriptManager.GetCurrent(ParentPage).RegisterPostBackControl(checkBox) in the Template (before adding to the Controls collection)...
What I have been able to diagnose this far is that I'm getting a JavaScript error, which seems to be AJAX-related from what I've found via Google searching... I am getting the "PageRequestManagerParserErrorException" error... which is what led me to trying [C] and [D] above...
When I tried [D] above, I was able to see Page_Init/Load firing but I still get an exception - but oddly enough it's related to the GridClientSelectColumn for the current grid... The server-side exception message was "Multiple controls with the same ID 'GridClientSelectColumnSelectCheckBox' were found. FindControl requires that controls have unique IDs."
What is the appropriate approach to achieve these goals? My desired functionality would be for the CheckedChanged event handler code to reside in the User Control itself - and not the template control...
I have a asp:TextBox and RegExpTextBoxSetting that connected to it.
I have 2 qustions:
1. Can the RegExpTextBoxSetting use with client function for validation? (instead the RegularExpression)
I want that the checking will done by the function.
2. Can I connect the RegExpTextBoxSetting to RadTextBox?
In the examples, its working only with the asp:TextBox !
Thanks.
<telerik:AjaxSetting AjaxControlID="gvManageUsers">
<UpdatedControls>
<telerik:AjaxUpdatedControl LoadingPanelID="RadAjaxLoadingPanel" ControlID="gvManageUsers" />
<telerik:AjaxUpdatedControl LoadingPanelID="RadAjaxLoadingPanel" ControlID="radPanel" />
</UpdatedControls>
</telerik:AjaxSetting>
Now When i try to update the radgrid from the radajax panel im unable to do that.In the code the grid is getting binded but it is not reflected on the UI.
I am using the below code
<
telerik:AjaxSetting AjaxControlID="radPanel">
<UpdatedControls>
<telerik:AjaxUpdatedControl LoadingPanelID="RadAjaxLoadingPanel" ControlID="gvManageUsers" />
</UpdatedControls>
</telerik:AjaxSetting>
Any help is greatly appreciated
Regards
Abid