or
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager><div> <telerik:RadGrid ID="TGrid" runat="server" Visible="true" AllowPaging="true" AllowSorting="true" PageSize="20" ScrollHeight="100px" ViewStateMode="Enabled" OnNeedDataSource="RadGrid1_NeedDataSource" OnPreRender="RadGrid1_PreRender" AutoGenerateColumns="false" AllowSelection="False" AllowMultiRowSelection="false" AllowMultiRowEdit="true" > <MasterTableView runat="server" HeaderStyle-Wrap="False" AllowCustomSorting="true" AllowMultiColumnSorting="false" RetrieveAllDataFields="false" EnableColumnsViewState="false" EditFormSettings-EditColumn-Visible="false" AdditionalDataFieldNames="Cow_ID" DataKeyNames="Cow_ID" EditMode="InPlace"> <Columns> <telerik:GridBoundColumn DataField="Cow_ID" HeaderText="MiHub ID" DataType="System.Int32" ReadOnly="true" HeaderStyle-Width="6em" /> <telerik:GridBoundColumn DataField="COW_EID" HeaderText="Electronic ID" DataType="System.String" ReadOnly="true" HeaderStyle-Width="12em" /> <telerik:GridBoundColumn DataField="COW_LifeId" HeaderText="Birth ID" DataType="System.String" ReadOnly="true" HeaderStyle-Width="8em" /> <telerik:GridBoundColumn DataField="COW_VID" HeaderText="Current Visual ID" DataType="System.Int32" ReadOnly="true" HeaderStyle-Width="8em" /> <telerik:GridTemplateColumn DataField="COW_VID" HeaderText="New Visual ID" DataType="System.Int32" ReadOnly="false" HeaderStyle-Width="15em"> <EditItemTemplate> <telerik:RadNumericTextBox runat="server" ID="tbNewVisualID" SelectionOnFocus="SelectAll" AutoPostBack="false" MinValue="0" MaxValue="999999"> <NumberFormat DecimalDigits="0" GroupSeparator="" /> <ClientEvents OnKeyPress="TelerikVisualIDKeyPress" OnValueChanged="TelerikValueChanged" /> </telerik:RadNumericTextBox> <span class="errorText" style="display: none">*NOT UNIQUE*</span> </EditItemTemplate> </telerik:GridTemplateColumn> </Columns> </MasterTableView> </telerik:RadGrid></div>public partial class _Default : System.Web.UI.Page{ protected void Page_Load(object sender, EventArgs e) { } protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e) { var data = new List<object>(); for (int i = 0; i < 1000; i++) { data.Add(new {Cow_Id = i, Cow_EID = i,cow_LifeId = i, Cow_VID = i}); } TGrid.DataSource = data; } protected void RadGrid1_PreRender(object sender, EventArgs e) { foreach (GridItem item in TGrid.MasterTableView.Items) { if (item is GridEditableItem) { GridEditableItem editableItem = item as GridDataItem; editableItem.Edit = true; } } TGrid.Rebind(); }}editableItem.Edit = true; then changing the page size works as expected, but then the column is not editable. Any thoughts?@{
Html.Telerik().Grid(Model) .Name("Grid") .DataBinding(dataBinding => { dataBinding.Ajax() .Select("Select", "MyController") .Insert("Insert", "MyController") .Update("Update", "MyController") .Delete("Delete", "MyController"); }) .ClientEvents(events => events .OnDataBinding("onDataBinding") .OnComplete("onComplete") .OnEdit("onEdit") .OnRowDataBound("onRowDataBound")) .Columns(columns => { columns.Command(commands => { commands.Edit().ButtonType(GridButtonType.Image); commands.Delete().ButtonType(GridButtonType.Image); }).Width(30); ; columns.Bound(o => o.Id); columns.Bound(o => o.col1); .Aggregate(aggregates => aggregates.Sum()) .GroupFooterTemplate(@<text>@item.Sum</text>); columns.Bound(o => o.col2) .Aggregate(aggregates => aggregates.Sum()) .GroupFooterTemplate(@<text>@item.Sum</text>); columns.Bound(o => o.col3) .Aggregate(aggregates => aggregates.Sum()) .GroupFooterTemplate(@<text>@item.Sum</text>); }) .CellAction(cell => { if ((cell.Column.Member == "col1") { cell.HtmlAttributes["style"] = "background-color: red"; } }) .Sortable(sorting => sorting .SortMode(GridSortMode.MultipleColumn) ) .Filterable() .Render(); }
}
public class invoicer{ public invoicer() { // // TODO: Add constructor logic here // string currentSession = HttpContext.Current.Session.SessionID; DataTable dt = GetTable(); HttpContext.Current.Session.Add(currentSession, dt); } public class MyTemplate : ITemplate { private string colname; protected Label lControl; public MyTemplate(string cName) { colname = cName; } public void InstantiateIn(System.Web.UI.Control container) { lControl = new Label(); lControl.ID = "Label-DurationType"; lControl.DataBinding += new EventHandler(lControl_DataBinding); container.Controls.Add(lControl); } public void lControl_DataBinding(object sender, EventArgs e) { Label l = (Label)sender; GridDataItem container = (GridDataItem)l.NamingContainer; l.Text = ((DataRowView)container.DataItem)[colname].ToString() + "<br />"; } } public class MyEditTemplate : IBindableTemplate { public void InstantiateIn(Control container) { GridDataItem item = ((GridDataItem)(container.NamingContainer)); DropDownList drop = new DropDownList(); drop.ID = "DurationType-DDL"; drop.DataSource = (DataTable)GetTableForDropDown(); drop.DataTextField = "DurationType"; drop.DataValueField = "DurationType"; container.Controls.Add(drop); } public System.Collections.Specialized.IOrderedDictionary ExtractValues(System.Web.UI.Control container) { OrderedDictionary od = new OrderedDictionary(); od.Add("DurationType", ((DropDownList)(((GridDataItem)(container)).FindControl("DurationType-DDL"))).DataValueField); return od; } } protected void grid_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e) { if (e.Item is GridEditFormItem && e.Item.IsInEditMode) { GridEditFormItem editItem = (GridEditFormItem)e.Item; DropDownList ddl = (DropDownList)editItem.FindControl("DurationType-DDL"); ddl.DataSource = (DataTable)GetTableForDropDown(); ddl.DataTextField = "DurationType"; ddl.DataValueField = "DurationType"; ddl.SelectedIndex = editItem.ItemIndex; } } public void DefineGridStructure(int i, PlaceHolder ph) { RadGrid grid = new RadGrid(); grid.ID = "RadGrid" + i.ToString(); grid.NeedDataSource += new GridNeedDataSourceEventHandler(grid_NeedDataSource); grid.AutoGenerateEditColumn = true; grid.AutoGenerateDeleteColumn = true; grid.AllowAutomaticInserts = false; grid.Width = Unit.Percentage(100); grid.PageSize = 15; grid.AllowPaging = true; grid.AllowFilteringByColumn = true; grid.PagerStyle.Mode = GridPagerMode.NextPrevAndNumeric; grid.AutoGenerateColumns = false; grid.MasterTableView.Width = Unit.Percentage(100); grid.MasterTableView.CommandItemDisplay = GridCommandItemDisplay.TopAndBottom; grid.AllowAutomaticDeletes = false; grid.AllowAutomaticUpdates = false; grid.ItemDataBound += new GridItemEventHandler(grid_ItemDataBound); grid.InsertCommand += grid_InsertCommand; grid.DeleteCommand += grid_DeleteCommand; grid.UpdateCommand += grid_UpdateCommand; grid.MasterTableView.DataKeyNames = new string[] { "RowNumber" }; GridBoundColumn boundColumn = new GridBoundColumn(); boundColumn.DataField = "RowNumber"; boundColumn.HeaderText = "RowNumber"; boundColumn.ReadOnly = true; grid.MasterTableView.Columns.Add(boundColumn); boundColumn = new GridBoundColumn(); boundColumn.DataField = "Size"; boundColumn.HeaderText = "Size"; grid.MasterTableView.Columns.Add(boundColumn); boundColumn = new GridBoundColumn(); boundColumn.DataField = "Description"; boundColumn.HeaderText = "Description"; grid.MasterTableView.Columns.Add(boundColumn); boundColumn = new GridBoundColumn(); boundColumn.DataField = "Quantity"; boundColumn.HeaderText = "Quantity"; grid.MasterTableView.Columns.Add(boundColumn); boundColumn = new GridBoundColumn(); boundColumn.DataField = "Unit"; boundColumn.HeaderText = "Unit"; grid.MasterTableView.Columns.Add(boundColumn); boundColumn = new GridBoundColumn(); boundColumn.DataField = "Duration"; boundColumn.HeaderText = "Duration"; grid.MasterTableView.Columns.Add(boundColumn); GridTemplateColumn objGridTemplateColumn = new GridTemplateColumn(); objGridTemplateColumn.HeaderText = "DurationType"; objGridTemplateColumn.DataField = "DurationType"; objGridTemplateColumn.ItemTemplate = new MyTemplate("DurationType"); objGridTemplateColumn.EditItemTemplate = new MyEditTemplate(); grid.MasterTableView.Columns.Add(objGridTemplateColumn); boundColumn = new GridBoundColumn(); boundColumn.DataField = "Amount"; boundColumn.HeaderText = "Amount"; grid.MasterTableView.Columns.Add(boundColumn); grid.MasterTableView.EditMode = GridEditMode.InPlace; ph.Controls.Add(grid); } public void grid_UpdateCommand(object sender, GridCommandEventArgs e) { GridEditableItem editItem = e.Item as GridEditableItem; Hashtable newValues = new Hashtable(); newValues["RowNumber"] = (editItem["RowNumber"].Controls[0] as TextBox).Text; newValues["Size"] = (editItem["Size"].Controls[0] as TextBox).Text; newValues["Description"] = (editItem["Description"].Controls[0] as TextBox).Text; newValues["Quantity"] = (editItem["Quantity"].Controls[0] as TextBox).Text; newValues["Unit"] = (editItem["Unit"].Controls[0] as TextBox).Text; newValues["Duration"] = (editItem["Duration"].Controls[0] as TextBox).Text; newValues["DurationType"] = (editItem.FindControl("DurationType-DDL") as DropDownList).SelectedValue; newValues["Amount"] = (editItem["Amount"].Controls[0] as TextBox).Text; DataTable dtCurrentTable = (DataTable)HttpContext.Current.Session[HttpContext.Current.Session.SessionID]; foreach (DictionaryEntry entry in newValues) { dtCurrentTable.Rows[e.Item.ItemIndex][entry.Key.ToString()] = entry.Value; } } public void grid_DeleteCommand(object sender, GridCommandEventArgs e) { GridDataItem item = e.Item as GridDataItem; DataTable dt = (DataTable)HttpContext.Current.Session[HttpContext.Current.Session.SessionID]; dt.Rows.Remove(dt.Rows[item.ItemIndex]); ResetRowID(dt); } public void grid_InsertCommand(object sender, GridCommandEventArgs e) { GridEditableItem editedItem = e.Item as GridEditableItem; GridEditManager editMan = editedItem.EditManager; //Set new values Hashtable newValues = new Hashtable(); //The GridTableView will fill the values from all editable columns in the hash DataTable dtCurrentTable = (DataTable)HttpContext.Current.Session[HttpContext.Current.Session.SessionID]; DataRow dr = null; int count = dtCurrentTable.Rows.Count; count++; dr = dtCurrentTable.NewRow(); dr["RowNumber"] = count; newValues["RowNumber"] = count; newValues["Size"] = (editedItem["Size"].Controls[0] as TextBox).Text; newValues["Description"] = (editedItem["Description"].Controls[0] as TextBox).Text; newValues["Quantity"] = (editedItem["Quantity"].Controls[0] as TextBox).Text; newValues["Unit"] = (editedItem["Unit"].Controls[0] as TextBox).Text; newValues["Duration"] = (editedItem["Duration"].Controls[0] as TextBox).Text; newValues["DurationType"] = (editedItem.FindControl("DurationType-DDL") as DropDownList).SelectedValue; newValues["Amount"] = (editedItem["Amount"].Controls[0] as TextBox).Text; foreach (DictionaryEntry entry in newValues) { dr[entry.Key.ToString()] = entry.Value; } dtCurrentTable.Rows.Add(dr); } void grid_NeedDataSource(object sender, GridNeedDataSourceEventArgs e) { DataTable current = (DataTable)HttpContext.Current.Session[HttpContext.Current.Session.SessionID]; RadGrid grid = (RadGrid)sender; grid.DataSource = current; } static DataTable GetTable() { // // Here we create a DataTable with a few columns. // // Create Datatable to store all colums DataTable dt = new DataTable(); DataRow dr = null; dt.Columns.Add(new DataColumn("RowNumber", typeof(string))); dt.Columns.Add(new DataColumn("Size", typeof(string))); dt.Columns.Add(new DataColumn("Description", typeof(string))); dt.Columns.Add(new DataColumn("Quantity", typeof(string))); dt.Columns.Add(new DataColumn("Unit", typeof(string))); dt.Columns.Add(new DataColumn("Duration", typeof(string))); dt.Columns.Add(new DataColumn("DurationType", typeof(string))); dt.Columns.Add(new DataColumn("Amount", typeof(string))); dr = dt.NewRow(); dr["RowNumber"] = 1; dr["Size"] = string.Empty; dr["Description"] = string.Empty; dr["Quantity"] = string.Empty; dr["Unit"] = string.Empty; dr["Duration"] = string.Empty; dr["DurationType"] = string.Empty; dr["Amount"] = string.Empty; dt.Rows.Add(dr); dr = dt.NewRow(); dr["RowNumber"] = 2; dr["Size"] = string.Empty; dr["Description"] = string.Empty; dr["Quantity"] = string.Empty; dr["Unit"] = string.Empty; dr["Duration"] = string.Empty; dr["DurationType"] = string.Empty; dr["Amount"] = string.Empty; dt.Rows.Add(dr); dr = dt.NewRow(); dr["RowNumber"] = 3; dr["Size"] = string.Empty; dr["Description"] = string.Empty; dr["Quantity"] = string.Empty; dr["Unit"] = string.Empty; dr["Duration"] = string.Empty; dr["DurationType"] = string.Empty; dr["Amount"] = string.Empty; dt.Rows.Add(dr); dr = dt.NewRow(); dr["RowNumber"] = 4; dr["Size"] = string.Empty; dr["Description"] = string.Empty; dr["Quantity"] = string.Empty; dr["Unit"] = string.Empty; dr["Duration"] = string.Empty; dr["DurationType"] = string.Empty; dr["Amount"] = string.Empty; dt.Rows.Add(dr); dr = dt.NewRow(); dr["RowNumber"] = 5; dr["Size"] = string.Empty; dr["Description"] = string.Empty; dr["Quantity"] = string.Empty; dr["Unit"] = string.Empty; dr["Duration"] = string.Empty; dr["DurationType"] = string.Empty; dr["Amount"] = string.Empty; dt.Rows.Add(dr); return dt; } static DataTable GetTableForDropDown() { // // Here we create a DataTable with a few columns. // // Create Datatable to store all colums DataTable dt = new DataTable(); DataRow dr = null; dt.Columns.Add(new DataColumn("DurationType", typeof(string))); dr = dt.NewRow(); dr["DurationType"] = "Hours"; dt.Rows.Add(dr); dr = dt.NewRow(); dr["DurationType"] = "Days"; dt.Rows.Add(dr); dr = dt.NewRow(); dr["DurationType"] = "Weeks"; dt.Rows.Add(dr); dr = dt.NewRow(); dr["DurationType"] = "Months"; dt.Rows.Add(dr); return dt; } private void ResetRowID(DataTable dt) { int rowNumber = 1; if (dt.Rows.Count > 0) { foreach (DataRow row in dt.Rows) { row[0] = rowNumber; rowNumber++; } } }}public partial class Default : System.Web.UI.Page{ protected void Page_Init(object sender, System.EventArgs e) { invoicer inv = new invoicer(); inv.DefineGridStructure(1, PlaceHolder1); } protected void Page_Load(object sender, EventArgs e) { }}<telerik:GridDateTimeColumn DataField="NULLABLE_TIMESHEET_ITEM_DATE" HeaderText="Date" PickerType="DatePicker" DataFormatString="{0:dd/MM/yyyy}" UniqueName="DateTimeColumEditor"> <HeaderStyle Width="120px" /></telerik:GridDateTimeColumn><telerik:GridDateTimeColumn HeaderText="Start Time" PickerType="TimePicker" DataField="NULLABLE_START_TIME" UniqueName="StartTimeColumn" DataFormatString="{0:HH:mm}" ColumnEditorID="DateTimeColumEditor"> <HeaderStyle Width="105px" /></telerik:GridDateTimeColumn><telerik:GridDateTimeColumn HeaderText="End Time" PickerType="TimePicker" DataField="NULLABLE_END_TIME" UniqueName="EndTimeColumn" DataFormatString="{0:HH:mm}" ColumnEditorID="DateTimeColumEditor"> <HeaderStyle Width="105px" /></telerik:GridDateTimeColumn>
Could you please provide sample code for the new batch editing functionality for OnBatchEditCellValueChanged. I need to know the following:
1. The index of the row (to get values of other columns)
2. The ID of the column
3. Old value
4. New value
Thank you,
-Sam
I installed ASP.NET Ajax. I chose the Visual Studio 2013 option. I see no Telerik templates when I select New Project.
I am using VS 2013 RC on Windows 8.1 RTM.
Any ideas about a fix?
bill b