I have a RadGrid that puts all rows in to editmode when the page loads, as outlined in the documentation using the PreRender event. I have also configured an UpdateAll item command to enable updating all records at once, as outlined in "Performing Batch Updates". The problem is that it updates all records even if no change was made. Is there someway to mark a row as dirty and only run the update query if it has changed?
Any suggestions on how I can limit the update to only fire if a change to the row was made?
| Protected Sub RadGrid1_ItemCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGrid1.ItemCommand |
| If e.CommandName = "UpdateAll" Then |
| For Each editedItem As GridEditableItem In RadGrid1.EditItems |
| Dim newValues As Hashtable = New Hashtable |
| e.Item.OwnerTableView.ExtractValuesFromItem(newValues, editedItem) |
| sdsSODetails.UpdateCommand = String.Format("UPDATE rx_srorder_extend SET STOP_NO='{0}', PLAN_REC_DATE='{1}', CONF_REC_DATE='{2}', CONF_NO='{3}', CONF_BY='{4}', CHANGED_BY='{6}' WHERE SRORDER_ID='{7}' IF @@ROWCOUNT = 0 INSERT INTO rx_srorder_extend (SRORDER_ID, PLAN_REC_DATE, CONF_REC_DATE, CONF_NO, CONF_BY, STOP_NO, CHANGED_BY) VALUES ('{7}', '{1}','{2}','{3}','{4}','{0}','{6}')", newValues("STOP_NO"), newValues("PLAN_REC_DATE"), newValues("CONF_REC_DATE"), newValues("CONF_NO"), newValues("CONF_BY"), newValues("SCHED_STATUS_ID"), newValues("CHANGED_BY"), editedItem.GetDataKeyValue("SRORDER_ID").ToString()) |
| sdsSODetails.Update() |
| Next |
| End If |
| End Sub |
| Private Sub RadGrid1_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles RadGrid1.PreRender |
| If Not IsPostBack Then |
| For Each item As GridItem In RadGrid1.MasterTableView.Items |
| If TypeOf item Is GridEditableItem Then |
| Dim editableItem As GridEditableItem = CType(item, GridDataItem) |
| editableItem.Edit = True |
| End If |
| Next |
| RadGrid1.Rebind() |
| End If |
| End Sub |

| <ajax:RadComboBox runat="server" ID="RadComboA" DataSource="<%# getApp() %>" OnSelectedIndexChanged="BindSecondCombo" |
| DataTextField="Selection" AutoPostBack ="true" |
| DataValueField="AppId" |
| SelectedValue='<%# DataBinder.Eval(Container.DataItem, "AppId") %>'></ajax:RadComboBox> |
| Public Sub BindSecondCombo(ByVal sender As Object, ByVal e As Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs) |
| Dim radComboA As RadComboBox |
| Dim radComboB As RadComboBox |
| Dim editItem As GridDataInsertItem |
| radComboA = CType(sender, RadComboBox) |
| editItem = CType(radCombo1.NamingContainer, GridDataInsertItem) |
| radComboB = CType(editItem.FindControl("radComboB"), RadComboBox) |
| If radComboB Is Nothing = False Then |
| radComboB.ClearSelection() |
| radComboB.DataSource = getRecordByType(7, radComboA.SelectedValue, "", "", "", "", "") |
| radComboB.DataTextField = "modulename" |
| radComboB.DataValueField = "moduleid" |
| radComboB.DataBind() |
| End If |
| End Sub |
Hi,
I have a question regarding GridDropDownColumn
In a Grid, i want the field prodtype to be a dropdown, where i can pick a value from ANOTHER table, when i update
or insert in the grid.
I know i can do it like this, but in this example, the values come from the same table as the grid is build on:
<telerik:GridDropDownColumn
DataSourceID="SqlDataSource1"
ListTextField="prodtype" ListValueField="prodtype"
UniqueName="prodtype" SortExpression="prodtype"
HeaderText="prodtype" DataField="prodtype">
</telerik:GridDropDownColumn>
Hope i can do it without any code.
Br
Gert Petersen
| private void fncGridData(){ |
| try |
| { |
| DataView dvDataView=new DataView(); |
| dvDataView = ((DataTable)Cache["Materials"]).DefaultView; |
| if (lstSubcategories.CheckedItems.Count == lstSubcategories.Items.Count) |
| { |
| dvDataView.RowFilter = ""; |
| } |
| else if(lstSubcategories.CheckedItems.Count==0){ |
| dvDataView.RowFilter = "id_sub_category=-1"; |
| } |
| else { |
| dvDataView.RowFilter = "id_sub_category IN (" + fncQueryComplement() + ")"; |
| } |
| RadGrid1.DataSource = (DataTable)Cache["Materials"]; |
| } |
| finally |
| { |
| SqlConnection.Close(); |
| } |
| } |
| if (e.Item is GridFilteringItem && string.IsNullOrEmpty(Grid.MasterTableView.FilterExpression)) |
| { |
| e.Item.Display = false; |
| } |
| else if (e.Item is GridCommandItem && !string.IsNullOrEmpty(Grid.MasterTableView.FilterExpression)) |
| { |
| var toolBar = e.Item.FindControl("ToolBar") as RadToolBar; |
| (toolBar.FindButtonByCommandName("Filter") as RadToolBarButton).Checked = true; |
| } |
| function ToolBar_ClientButtonClicked(sender, args) |
| { |
| var button = args.get_item(); |
| switch (button.get_commandName()) |
| { |
| case 'Filter': |
| if (button.get_isChecked()) |
| { |
| $find('<%= Grid.ClientID %>').get_masterTableView().showFilterItem(); |
| } |
| else |
| { |
| var masterTableView = $find("<%= Grid.ClientID %>").get_masterTableView(); |
| masterTableView.filter("Description", "", Telerik.Web.UI.GridFilterFunction.NoFilter); |
| masterTableView.filter("Class", "", Telerik.Web.UI.GridFilterFunction.NoFilter); |
| masterTableView.filter("DefaultCategory", "", Telerik.Web.UI.GridFilterFunction.NoFilter); |
| masterTableView.hideFilterItem(); |
| } |
| break; |
| } |
| } |
Hi,
I need to create hierarchical rad grid programatically using DataTable, but I'm having a problem in settng the data source for level 1 hierarchy. When I try to expand the child table, an exception is thrown as
"Exception Details: System.Data.SyntaxErrorException: Syntax error: Missing operand before 'Is' operator."
Kindly help me out regarding this issue. I have attached my code and exception trace. Thanks
Regards
Muhammad Farjad
----------------------------------------------------------------------------------------------------------------------------------------------------------------------
<body>
<form id="form1" runat="server">
<telerik:RadScriptManager ID="RadScriptManager1" runat="server">
<Scripts>
<asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js" />
<asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQuery.js" />
</Scripts>
</telerik:RadScriptManager>
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
</telerik:RadAjaxManager>
<div>
<telerik:RadGrid ID="RadGrid1" runat="server" ondetailtabledatabind="RadGrid1_DetailTableDataBind">
</telerik:RadGrid>
</div>
</form>
</body>
---------------------------------------------------- Code Behind File ----------------------------------------------------------------------------
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Configuration;
using System.Web.Security;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Telerik.Web.UI;
public partial class Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
//Add grand father table
DataTable grandFatherTable = CreateDataTable("GrandFather");
AddDataToTable("usman", "Usman", "Mansur", grandFatherTable);
AddDataToTable("adnan", "Adnan", "Ahmad", grandFatherTable);
AddDataToTable("nabeel", "Nabeel", "Ahmed", grandFatherTable);
RadGrid1.DataSource = grandFatherTable;
RadGrid1.MasterTableView.DataKeyNames = new string[] { "username" };
RadGrid1.Width = Unit.Percentage(98);
RadGrid1.PageSize = 5;
RadGrid1.AllowPaging = true;
//RadGrid1.PagerStyle.Mode = GridPagerMode.NextPrevAndNumeric;
RadGrid1.AutoGenerateColumns = false;
RadGrid1.Skin = "Web20";
RadGrid1.MasterTableView.PageSize = 15;
RadGrid1.MasterTableView.Width = Unit.Percentage(100);
GridBoundColumn boundColumn;
boundColumn = new GridBoundColumn();
RadGrid1.MasterTableView.Columns.Add(boundColumn);
boundColumn.DataField = "username";
boundColumn.HeaderText = "User Name";
boundColumn = new GridBoundColumn();
RadGrid1.MasterTableView.Columns.Add(boundColumn);
boundColumn.DataField = "firstname";
boundColumn.HeaderText = "First Name";
boundColumn = new GridBoundColumn();
RadGrid1.MasterTableView.Columns.Add(boundColumn);
boundColumn.DataField = "lastname";
boundColumn.HeaderText = "Last Name";
//Add Father table
DataTable fatherTable = CreateDataTable("Father");
AddDataToTable("usman", "u1", "u2", fatherTable);
AddDataToTable("adnan", "a1", "a2", fatherTable);
AddDataToTable("nabeel", "n1", "n2", fatherTable);
GridTableView tableViewFather = new GridTableView(RadGrid1);
tableViewFather.Width = Unit.Percentage(100);
tableViewFather.DataSource = fatherTable;
tableViewFather.DataKeyNames = new string[] { "username" };
GridRelationFields relationFields = new GridRelationFields();
relationFields.MasterKeyField = "username";
relationFields.DetailKeyField = "username";
tableViewFather.ParentTableRelation.Add(relationFields);
RadGrid1.MasterTableView.DetailTables.Add(tableViewFather);
boundColumn = new GridBoundColumn();
tableViewFather.Columns.Add(boundColumn);
boundColumn.DataField = "username";
boundColumn.HeaderText = "User Name";
boundColumn = new GridBoundColumn();
tableViewFather.Columns.Add(boundColumn);
boundColumn.DataField = "firstname";
boundColumn.HeaderText = "First Name";
boundColumn = new GridBoundColumn();
tableViewFather.Columns.Add(boundColumn);
boundColumn.DataField = "lastname";
boundColumn.HeaderText ="Last Name";
}
}
private DataTable CreateDataTable(string tableName)
{
DataTable myDataTable = new DataTable(tableName);
DataColumn myDataColumn;
myDataColumn = new DataColumn();
myDataColumn.DataType = Type.GetType("System.String");
myDataColumn.ColumnName = "username";
myDataTable.Columns.Add(myDataColumn);
myDataColumn = new DataColumn();
myDataColumn.DataType = Type.GetType("System.String");
myDataColumn.ColumnName = "firstname";
myDataTable.Columns.Add(myDataColumn);
myDataColumn = new DataColumn();
myDataColumn.DataType = Type.GetType("System.String");
myDataColumn.ColumnName = "lastname";
myDataTable.Columns.Add(myDataColumn);
return myDataTable;
}
private void AddDataToTable(string username, string firstname, string lastname, DataTable myTable)
{
DataRow row;
row = myTable.NewRow();
//row["id"] = Guid.NewGuid().ToString();
row["username"] = username;
row["firstname"] = firstname;
row["lastname"] = lastname;
myTable.Rows.Add(row);
}
protected void RadGrid1_DetailTableDataBind(object source, GridDetailTableDataBindEventArgs e)
{
DataTable fatherTable = CreateDataTable("Father");
AddDataToTable("usman", "u1", "u2", fatherTable);
AddDataToTable("adnan", "a1", "a2", fatherTable);
AddDataToTable("nabeel", "n1", "n2", fatherTable);
e.DetailTableView.DataSource = fatherTable;
}
}
---------------------------------------------------------- exception ------------------------------------------------------------------------
Server Error in '/RadHierarchicalGrid' Application.
--------------------------------------------------------------------------------
Syntax error: Missing operand before 'Is' operator.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.SyntaxErrorException: Syntax error: Missing operand before 'Is' operator.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[SyntaxErrorException: Syntax error: Missing operand before 'Is' operator.]
System.Data.ExpressionParser.Parse() +4824040
System.Data.DataExpression..ctor(DataTable table, String expression, Type type) +121
System.Data.DataView.set_RowFilter(String value) +153
System.Data.LinqDataView.set_RowFilter(String value) +53
Telerik.Web.UI.GridEnumerableFromDataView.PerformTransformation() +375
Telerik.Web.UI.GridEnumerableFromDataView.TransformEnumerable() +21
Telerik.Web.UI.GridTableView.GetEnumerator(Boolean useDataSource, GridEnumerableBase resolvedDataSource, ArrayList dataKeysArray) +105
Telerik.Web.UI.GridTableView.CreateControlHierarchy(Boolean useDataSource) +432
Telerik.Web.UI.GridTableView.CreateChildControls(IEnumerable dataSource, Boolean useDataSource) +500
System.Web.UI.WebControls.CompositeDataBoundControl.PerformDataBinding(IEnumerable data) +57
System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback(IEnumerable data) +114
System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +31
System.Web.UI.WebControls.DataBoundControl.PerformSelect() +142
Telerik.Web.UI.GridTableView.PerformSelect() +4
System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +73
Telerik.Web.UI.GridTableView.DataBind() +224
Telerik.Web.UI.GridDataItem.OnExpand() +272
Telerik.Web.UI.GridItem.set_Expanded(Boolean value) +109
Telerik.Web.UI.GridExpandCommandEventArgs.ExecuteCommand(Object source) +34
Telerik.Web.UI.RadGrid.OnBubbleEvent(Object source, EventArgs e) +134
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37
Telerik.Web.UI.GridItem.OnBubbleEvent(Object source, EventArgs e) +115
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37
System.Web.UI.WebControls.Button.OnCommand(CommandEventArgs e) +118
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +166
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565
--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.4927; ASP.NET Version:2.0.50727.4927