| If e.CommandName = "ExpandCollapse" Then |
| For Each item As GridItem In e.Item.OwnerTableView.Items |
| If item.Expanded = True Then |
| item.Expanded = False |
| End If |
| Next |
| End If |
Hi,
I'm using a demo call update/insert/delete when the EnableViewState property of the grid is set to false.
If i press cancel button ni editform anyway insert record.
Wha can i do?
Regards...
protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)
{
if (e.CommandName == RadGrid.UpdateCommandName)
{
RadGrid1.DataSource =
null;
}
else if (e.CommandName == RadGrid.EditCommandName)
{
Session[
"initEdit"] = true;
Session[
"updateFlag"] = true;
}
else if (e.CommandName == RadGrid.InitInsertCommandName)
{
Session[
"insertFlag"] = true;
}
else if(e.CommandName == RadGrid.DeleteCommandName)
{
string ID = e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["EmployeeID"].ToString();
DataTable employeesTable = (DataTable)Session["employeesTable"];
if (employeesTable.Rows.Find(ID) != null)
{
employeesTable.Rows.Find(ID).Delete();
employeesTable.AcceptChanges();
Session[
"employeesTable"] = employeesTable;
}
}
}
protected void RadGrid1_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
{
if(Session["updateFlag"] != null && Session["initEdit"] != null)
{
DataTable employeesTable = (DataTable)Session["employeesTable"];
for (int i = 0; i < RadGrid1.EditIndexes.Count; i++)
{
GridDataItem dataItem = RadGrid1.MasterTableView.Items[RadGrid1.EditIndexes[i]] as GridDataItem;
GridEditableItem editItem = (dataItem.OwnerTableView.EditMode == GridEditMode.InPlace) ? (GridEditableItem)dataItem : (GridEditableItem)dataItem.EditFormItem;
GridEditManager mng = editItem.EditManager;
foreach (GridColumn column in dataItem.OwnerTableView.Columns)
{
if (column is IGridEditableColumn)
{
IGridEditableColumn editedColumn = column as IGridEditableColumn;
IGridColumnEditor editor = mng.GetColumnEditor(editedColumn);
string editorType = editor.ToString();
string editorText = null;
if (editor is GridTextColumnEditor)
{
editorText = (editor
as GridTextColumnEditor).Text;
}
try
{
DataRow[] changedRows = employeesTable.Select("EmployeeID = " + editItem.OwnerTableView.DataKeyValues[editItem.ItemIndex]["EmployeeID"]);
changedRows[0][column.UniqueName] = editorText;
}
catch (Exception ex)
{
RadGrid1.Controls.Add(
new LiteralControl("Unable to update Employee. Reason: " + ex.Message));
}
}
}
}
employeesTable.AcceptChanges();
Session[
"employeesTable"] = employeesTable;
Session[
"updateFlag"] = false;
Session[
"editIndex"] = null;
}
else if (Session["insertFlag"] != null)
{
DataTable employeesTable = (DataTable)Session["employeesTable"];
DataRow newRow = employeesTable.NewRow();
GridEditableItem insertItem = RadGrid1.MasterTableView.GetInsertItem();
GridEditManager mng = insertItem.EditManager;
foreach (GridColumn column in insertItem.OwnerTableView.Columns)
{
if (column is IGridEditableColumn)
{
IGridEditableColumn editedColumn = column as IGridEditableColumn;
IGridColumnEditor editor = mng.GetColumnEditor(editedColumn);
string editorType = editor.ToString();
string editorText = null;
if (editor is GridTextColumnEditor)
{
editorText = (editor
as GridTextColumnEditor).Text;
}
try
{
newRow[column.UniqueName] = editorText;
}
catch (Exception ex)
{
RadGrid1.Controls.Add(
new LiteralControl("Unable to insert into Employees. Reason: " + ex.Message));
}
}
}
//This should not be applied when updating directly the database
newRow[
"EmployeeID"] = (int)employeesTable.Rows[employeesTable.Rows.Count - 1]["EmployeeID"] + 1;
employeesTable.Rows.Add(newRow);
Session[
"employeesTable"] = employeesTable;
Session[
"insertFlag"] = null;
}
Session[
"initEdit"] = null;
RadGrid1.DataSource = (
DataTable)Session["employeesTable"];
}
| <script type="text/javascript"> |
| function realPostBack(eventTarget, eventArgument) |
| { |
| __doPostBack(eventTarget, eventArgument); |
| } |
| </script> |
| <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" DefaultLoadingPanelID="AjaxLoadingPanel1"> |
| <AjaxSettings> |
| <telerik:AjaxSetting AjaxControlID="rdgResults"> |
| <UpdatedControls> |
| <telerik:AjaxUpdatedControl ControlID="rdgResults" LoadingPanelID="AjaxLoadingPanel1" /> |
| </UpdatedControls> |
| </telerik:AjaxSetting> |
| </AjaxSettings> |
| </telerik:RadAjaxManager> |
| <asp:panel id="pnlsearch" runat="server" DefaultButton="btnSearch"> |
| ... |
| <telerik:RadGrid ID="rdgResults" runat="server" AllowPaging="True" AllowSorting="True" EnableEmbeddedSkins="False" Skin="radGridSkin" Width="100%" EnableOutsideScripts="True" GridLines="None"> |
| <MasterTableView AutoGenerateColumns="False" AllowNaturalSort="False" NoMasterRecordsText="No Special Permission Requests Found." |
| PageSize="20" DataKeyNames="RequestID" BorderColor="#B5E9AD"> |
| ... |
| <Columns> |
| ... |
| <telerik:GridTemplateColumn UniqueName="tmpEditColumn"> |
| <HeaderTemplate> |
| Edit |
| </HeaderTemplate> |
| <ItemTemplate> |
| <div class="functionButtons"> |
| <asp:Button runat="server" Text="" CssClass="btnEdit" ID="btnEdit" CommandName="EditCustom" /> |
| </div> |
| </ItemTemplate> |
| </telerik:GridTemplateColumn> |
| </Columns> |
| </MasterTableView> |
| </telerik:RadGrid> |
| <asp:panel id="pnlReqEntry" runat="server"> |
| Protected Sub rdgResults_ItemCreated(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles rdgResults.ItemCreated |
| If (TypeOf e.Item Is GridDataItem) Then |
| Dim dataItem As GridDataItem = CType(e.Item, GridDataItem) |
| Dim button1 As Button = CType(dataItem("tmpEditColumn").FindControl("btnEdit"), Button) |
| button1.Attributes.Add("onclick", String.Format("realPostBack('{0}', '{1}'); return false;", button1.UniqueID, button1.CommandArgument)) |
| End If |
| End Sub |
| <compilation debug="true"> |
| <assemblies> |
| <add assembly="Telerik.Web.Design, Version=2009.2.826.20, Culture=neutral, PublicKeyToken=121FAE78165BA3D4" /> |
| <add assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /> |
| </assemblies> |
| </compilation> |
| <httpHandlers> |
| <add path="Telerik.Web.UI.WebResource.axd" type="Telerik.Web.UI.WebResource, Telerik.Web.UI, Version=2009.2.826.20, Culture=neutral, PublicKeyToken=121fae78165ba3d4" verb="*" validate="false" /> |
| </httpHandlers> |
| </system.web> |
| <system.webServer> |
| <validation validateIntegratedModeConfiguration="false" /> |
| <handlers> |
| <add name="Telerik_Web_UI_WebResource_axd" verb="*" preCondition="integratedMode" path="Telerik.Web.UI.WebResource.axd" type="Telerik.Web.UI.WebResource" /> |
| </handlers> |
Andrew

| <telerik:RadContextMenu ID="RCMU" runat="server" ... > |
| <Items> |
| ... |
| <telerik:RadMenuItem Value="5"> |
| <ItemTemplate> |
| <telerik:RadComboBox ID="CMRDDLC" runat="server" |
| ShowMoreResultsBox="false" EnableVirtualScrolling="true" EnableItemCaching="true" |
| EnableTextSelection="true" EnableViewState="False" |
| EnableLoadOnDemand="true" ZIndex="10000" |
| OnClientItemsRequesting="OnClientItemsRequesting"> |
| <WebServiceSettings Path="~/.asmx" Method="GetMethod" /> |
| <CollapseAnimation Duration="100" Type="OutQuint" /> |
| </telerik:RadComboBox> |
| </ItemTemplate> |
| </telerik:RadMenuItem> |
| ... |
| </Items> |
| </telerik:RadContextMenu> |
I recently purchased the AJAX RADControls since read that it is one of the best AJAX libraries available.
I am trying to move my web apps into AJAX. I use server controls only for the initial page rendering of the DOM elements and then make web-service calls (using PageMethods or WCF) to populate or manipulate any grids, forms or data that exist in the page.
I added some of the Telerik controls to replace plain HTML tags (such as drop-down lists, inputs, etc.) but it is difficult it is to find these controls in the DOM in order to manipulate them (especially when they are embedded within other ASP.Net server controls).
To find a Telerik Control I have to resort to such calls as:
var combo = $find("<%= RadComboBox1.ClientID %>");
var item = combo.findItemByText(text);
(By the way, this code above will NOT run when you place your script code in a separate JS file which is a best practice that I prefer to follow.)
I am trying to use these controls for 100% strictly data access via AJAX.
I don't need the ASP.Net engine to assign them an ID in the DOM, I want to control this ID myself so that I can more easily access them from my scripts.
Can I define my own Client IDs when I place controls on a page declaratively or programmatically?
Can I assign the Client IDs of the RADControls when using ASP.NET MVC?
Let me know if this level of control is possible with RADControls.
Klaus Barkhausen