I have a RadGrid that allow multiple selection...What i need is after the user select a few rows and after click on a button("DONE") I want to change that rows color for example to red and allow the reverse action...
For final I need to count in real time, How many rows are Red(DONE) and how many aren't and show a dialog to inform it.
this is my RadGrid on aspx page:
div> <telerik:RadGrid ID="RadGrid1" runat="server" GridLines="None" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" ViewStateMode="Disabled" Width="97%" enableajax="True" CssClass="productsGrid" CellSpacing="0" AllowFilteringByColumn="True" ShowFooter="True" Skin="Black" AllowMultiRowSelection="True" OnItemCommand="RadGrid1_ItemCommand" OnGridExporting="RadGrid1_GridExporting" OnNeedDataSource="RadGrid1_NeedDataSource"> <PagerStyle Mode="NextPrevAndNumeric"></PagerStyle> <ClientSettings AllowColumnsReorder="True" ReorderColumnsOnClient="True"> <Selecting AllowRowSelect="True" /> </ClientSettings> <MasterTableView GridLines="None" Width="100%" ViewStateMode="Disabled" CommandItemSettings-ShowExportToCsvButton="True" CommandItemSettings-ShowAddNewRecordButton="false" CommandItemDisplay="Top"> <Columns> <telerik:GridBoundColumn DataField="SequencialNumber" HeaderText="SequencialNumber" UniqueName="SequencialNumber" SortExpression="SequencialNumber"> </telerik:GridBoundColumn> <telerik:GridBoundColumn DataField="Priorities.Priority" HeaderText="Priority" UniqueName="Priority" FilterControlAltText="Filter Priority column" SortExpression="Priority" DataType="System.Int32"> </telerik:GridBoundColumn> <telerik:GridBoundColumn DataField="Staging.Process" HeaderText="Staging" UniqueName="Process" SortExpression="Process" FilterControlAltText="Filter Process column"> </telerik:GridBoundColumn> <telerik:GridBoundColumn DataField="SupplierCode" HeaderText="SupplierCode" UniqueName="SupplierCode" SortExpression="SupplierCode" FilterControlAltText="Filter SupplierCode column"> </telerik:GridBoundColumn> <telerik:GridBoundColumn DataField="MessageStatus" HeaderText="MessageStatus" UniqueName="MessageStatus" SortExpression="MessageStatus" FilterControlAltText="Filter MessageStatus column"> </telerik:GridBoundColumn> <telerik:GridBoundColumn DataField="DocumentType" HeaderText="DocumentType" UniqueName="DocumentType" FilterControlAltText="Filter DocumentType column" SortExpression="DocumentType"> </telerik:GridBoundColumn> <telerik:GridDateTimeColumn UniqueName="InvoiceCreationDate" DataField="InvoiceCreationDate" HeaderText="InvoiceCreationDate" FilterControlAltText="Filter InvoiceCreationDate column" SortExpression="InvoiceCreationDate"> <FilterTemplate> <telerik:RadDatePicker ID="RadDatePicker1" runat="server"> </telerik:RadDatePicker> </FilterTemplate> </telerik:GridDateTimeColumn> <telerik:GridBoundColumn DataField="SupplierVatNumber" FilterControlAltText="Filter SupplierVatNumber column" HeaderText="SupplierVatNumber" SortExpression="SupplierVatNumber" UniqueName="SupplierVatNumber"> </telerik:GridBoundColumn> </Columns> <ExpandCollapseColumn Visible="False"> <HeaderStyle Width="19px"></HeaderStyle> </ExpandCollapseColumn> <RowIndicatorColumn Visible="False"> <HeaderStyle Width="20px" /> </RowIndicatorColumn> </MasterTableView> <FilterMenu EnableImageSprites="False"> </FilterMenu> <HeaderContextMenu CssClass="GridContextMenu GridContextMenu_Default"> </HeaderContextMenu> </telerik:RadGrid>this is my code behind:
public partial class InvoicesScalingDefault : Microsoft.Practices.CompositeWeb.Web.UI.Page, IInvoicesScale { private InvoicesScalePresenter _presenter; public System.Collections.Generic.IList<Data.SapDocuments> SapDocuments { get; set; } protected void Page_Load(object sender, EventArgs e) { if (!this.IsPostBack) { this._presenter.OnViewInitialized(); } this._presenter.OnViewLoaded(); //string userLogin = Page.User.Identity.Name; } [CreateNew] public InvoicesScalePresenter Presenter { set { this._presenter = value; this._presenter.View = this; } } private void LoadData() { //Popular dados na Radlist SapDocumentsBO sapDocs = new SapDocumentsBO(); string user = Page.User.Identity.Name.Substring(Page.User.Identity.Name.IndexOf("\\") + 1); if ((user == "xxx") || (user == "xxx")) { this.SapDocuments = sapDocs.GetSapDocuments(); RadGrid1.DataSource = this.SapDocuments; } else { this.SapDocuments = sapDocs.GetSapDocumentsByUser(user); RadGrid1.DataSource = this.SapDocuments; } } protected void RadGrid1_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e) { LoadData(); } /// <summary> /// Export de todos os SequencialNumber da tabela para .csv /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void RadGrid1_ItemCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e) { if (e.CommandName == Telerik.Web.UI.RadGrid.ExportToCsvCommandName) { RadGrid1.MasterTableView.Columns.FindByUniqueName("SequencialNumber").Visible = true; RadGrid1.ExportSettings.IgnorePaging = true; int count = 0; foreach (GridColumn column in RadGrid1.Columns) { if (column.Visible) { if (count > 0) column.Visible = false; else count++; } } } } /// <summary> /// Método para formatar o sequencialNumber /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void RadGrid1_GridExporting(object sender, GridExportingArgs e) { e.ExportOutput = e.ExportOutput.Replace("\"\r\n\"", "\"\r\n\"'"); } } }32 Answers, 1 is accepted
foreach (GridDataItem item in RadGrid1.Items) //if (e.Item is GridDataItem && e.Item.OwnerTableView.Name == "ParentTable") // you can also identify details table/Item { if (item.Selected) // codition for item is selected. {
// set the cell color
TableCell cell = item["ColumnUniqueName"]; cell.BackColor = Color.Red;
// set the row color
item.BackColor = Drawing.Color.Red;
} }let me know if any concern.
Thanks,
Jayesh Goyani
what about the counting? For final I need to count in real time, How many rows are Red(DONE) and how many aren't and show a dialog to inform it.
A notification that appears allways there are selected items, saying that x items are DONE and y items missing??
Can you show me how to do that?
// if you are used pagging then set Allowpagging="False" hereint count = 0; foreach (GridDataItem item in RadGrid1.Items) //if (e.Item is GridDataItem && e.Item.OwnerTableView.Name == "ParentTable") // you can also identify details table/Item { if (item.Selected) // codition for item is selected. { // set the cell color TableCell cell = item["ColumnUniqueName"]; cell.BackColor = Color.Red; // set the row color item.BackColor = Drawing.Color.Red; count ++; } }int totalRowCount = RadGrid1.Items.Count;int SelectedRowCount = count ;// if you are used pagging then set Allowpagging="true" hereyou can get directly
SelectedRowCount = RadGrid1.SelectedItems.count;let me know if any concern.
Thanks,
Jayesh Goyani
Why?»
protected void RadButton1_Click(object sender, EventArgs e) { // if you are used pagging then set Allowpagging="False" here RadGrid1.AllowPaging = false; int count = 0; foreach (GridDataItem item in RadGrid1.Items) //if (e.Item is GridDataItem && e.Item.OwnerTableView.Name == "ParentTable") // you can also identify details table/Item { if (item.Selected) // codition for item is selected. { // set the cell color TableCell cell = item["SequencialNumber"]; cell.BackColor = Color.White; // set the row color item.BackColor = System.Drawing.Color.Red; count++; } } int totalRowCount = RadGrid1.Items.Count; int SelectedRowCount = count; RadGrid1.AllowPaging=true;The purpose is to select a row of the table and if i put :
TableCell
cell = item["SequencialNumber"];
I select a row on the middle of the table and I'm not catching it......Nothings happen
The proble is the never find a selected Item......It never gets inside the :
if (item.Selected) // codition for item is selected.
{ // set the cell color TableCell cell = item["ColumnUniqueName"]; cell.BackColor = Color.Red; // set the row color item.BackColor = Drawing.Color.Red; count ++; } protected void RadGrid1_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e) { LoadData(); } /// <summary> /// Export de todos os SequencialNumber da tabela para .csv /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void RadGrid1_ItemCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e) { if (e.CommandName == Telerik.Web.UI.RadGrid.ExportToCsvCommandName) { RadGrid1.MasterTableView.Columns.FindByUniqueName("SequencialNumber").Visible = true; RadGrid1.ExportSettings.IgnorePaging = true; int count = 0; foreach (GridColumn column in RadGrid1.Columns) { if (column.Visible) { if (count > 0) column.Visible = false; else count++; } } } } /// <summary> /// Método para formatar o sequencialNumber /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void RadGrid1_GridExporting(object sender, GridExportingArgs e) { e.ExportOutput = e.ExportOutput.Replace("\"\r\n\"", "\"\r\n\"'"); } protected void RadButton1_Click(object sender, EventArgs e) { // if you are used pagging then set Allowpagging="False" here RadGrid1.AllowPaging = false; int count = 0; foreach (GridDataItem item in RadGrid1.Items) //if (e.Item is GridDataItem && e.Item.OwnerTableView.Name == "ParentTable") // you can also identify details table/Item { if (item.Selected) // codition for item is selected. { //// set the cell color TableCell cell = item["SequencialNumber"]; cell.BackColor = Color.White; // set the row color item.BackColor = System.Drawing.Color.Red; count++; } } int totalRowCount = RadGrid1.Items.Count; int SelectedRowCount = count; RadGrid1.AllowPaging = true; // if you are used pagging then set Allowpagging="true" here } protected void RadButton2_Click(object sender, EventArgs e) { // if you are used pagging then set Allowpagging="False" here RadGrid1.AllowPaging = false; foreach (GridDataItem item in RadGrid1.Items) //if (e.Item is GridDataItem && e.Item.OwnerTableView.Name == "ParentTable") // you can also identify details table/Item { if (item.Selected) // codition for item is selected. { //// set the cell color TableCell cell = item["SequencialNumber"]; cell.BackColor = Color.White; // set the row color item.BackColor = System.Drawing.Color.Red; } } RadGrid1.AllowPaging = true; // if you are used pagging then set Allowpagging="true" here } } } In below example if you not set Allowpagging="false" then You can get only 5 as Total item but in real there are 15 items so allowpagging="false" is needed.
Let me know if any concern.
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="GridWithSelectedItem.aspx.cs" Inherits="TelerikTest.Web.GridWithSelectedItem" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"> <title></title> <style type="text/css"> .TextCss { background: red !important; } </style></head><body> <form id="form1" runat="server"> <div> <telerik:RadScriptManager ID="RadScriptManager1" runat="server"> </telerik:RadScriptManager> <telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="false" AllowPaging="true" PageSize="5" AllowMultiRowSelection="true" OnNeedDataSource="RadGrid1_NeedDataSource" OnItemDataBound="RadGrid1_ItemDataBound" Skin="Vista"> <MasterTableView DataKeyNames="ID"> <Columns> <telerik:GridBoundColumn DataField="ID" UniqueName="ID" HeaderText="ID"> </telerik:GridBoundColumn> <telerik:GridBoundColumn DataField="Name" UniqueName="Name" HeaderText="Name"> </telerik:GridBoundColumn> </Columns> </MasterTableView> <ClientSettings> <Selecting AllowRowSelect="true" /> </ClientSettings> </telerik:RadGrid> </div> <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" /> </form></body></html>using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using Telerik.Web.UI;using System.Drawing;namespace TelerikTest.Web{ public partial class GridWithSelectedItem : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void RadGrid1_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e) { dynamic data = new[] { new { ID = 1, Name ="Name1"}, new { ID = 2, Name = "Name2"}, new { ID = 3, Name = "Name3"}, new { ID = 4, Name = "Name4"}, new { ID = 5, Name = "Name5"}, new { ID = 6, Name ="Name6"}, new { ID = 7, Name = "Name7"}, new { ID = 8, Name = "Name8"}, new { ID = 9, Name = "Name9"}, new { ID = 10, Name = "Name10"}, new { ID = 11, Name ="Name11"}, new { ID = 12, Name = "Name12"}, new { ID = 13, Name = "Name13"}, new { ID = 14, Name = "Name14"}, new { ID = 15, Name = "Name15"} }; RadGrid1.DataSource = data; } protected void Button1_Click(object sender, EventArgs e) { RadGrid1.MasterTableView.AllowPaging = false; RadGrid1.Skin = "Black"; RadGrid1.Rebind(); int Selectedcount = 0; foreach (GridDataItem item in RadGrid1.Items) { if (item.Selected) { Selectedcount++; item.BackColor = Color.Red; } } Button1.Text = "Selected :(" + Selectedcount.ToString() + ")" + " Total :(" + RadGrid1.Items.Count.ToString() + ")"; RadGrid1.MasterTableView.AllowPaging = true; RadGrid1.SelectedItemStyle.CssClass = "TextCss"; RadGrid1.Rebind(); } protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e) { if (e.Item is GridDataItem) { GridDataItem item = (GridDataItem)e.Item; if (Convert.ToInt32(item.GetDataKeyValue("ID")) == 1 || Convert.ToInt32(item.GetDataKeyValue("ID")) == 3 || Convert.ToInt32(item.GetDataKeyValue("ID")) == 5) { item.Selected = true; } } } }}Thanks,
Jayesh Goyani
private void LoadData() { //Popular dados na Radlist SapDocumentsBO sapDocs = new SapDocumentsBO(); string user = Page.User.Identity.Name.Substring(Page.User.Identity.Name.IndexOf("\\") + 1); if ((user == "apsilva3") || (user == "scfreitas")) { this.SapDocuments = sapDocs.GetSapDocuments(); RadGrid1.DataSource = this.SapDocuments; } else { this.SapDocuments = sapDocs.GetSapDocumentsByUser(user); RadGrid1.DataSource = this.SapDocuments; } } protected void RadGrid1_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e) { LoadData(); } /// <summary> /// Export de todos os SequencialNumber da tabela para .csv /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void RadGrid1_ItemCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e) { if (e.CommandName == Telerik.Web.UI.RadGrid.ExportToCsvCommandName) { RadGrid1.MasterTableView.Columns.FindByUniqueName("SequencialNumber").Visible = true; RadGrid1.ExportSettings.IgnorePaging = true; int count = 0; foreach (GridColumn column in RadGrid1.Columns) { if (column.Visible) { if (count > 0) column.Visible = false; else count++; } } } } /// <summary> /// Método para formatar o sequencialNumber /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void RadGrid1_GridExporting(object sender, GridExportingArgs e) { e.ExportOutput = e.ExportOutput.Replace("\"\r\n\"", "\"\r\n\"'"); } protected void RadButton1_Click(object sender, EventArgs e) { // if you are used pagging then set Allowpagging="False" here RadGrid1.AllowPaging = false; int count = 0; foreach (GridDataItem item in RadGrid1.Items) //if (e.Item is GridDataItem && e.Item.OwnerTableView.Name == "ParentTable") // you can also identify details table/Item { if (item.Selected) // codition for item is selected. { //// set the cell color TableCell cell = item["SequencialNumber"]; cell.BackColor = Color.White; // set the row color item.BackColor = System.Drawing.Color.Red; count++; } } int totalRowCount = RadGrid1.Items.Count; int SelectedRowCount = count; RadGrid1.AllowPaging = true; // if you are used pagging then set Allowpagging="true" here } protected void RadButton2_Click(object sender, EventArgs e) { // if you are used pagging then set Allowpagging="False" here RadGrid1.MasterTableView.AllowPaging = false; foreach (GridDataItem item in RadGrid1.Items) //if (e.Item is GridDataItem && e.Item.OwnerTableView.Name == "ParentTable") // you can also identify details table/Item { if (item.Selected) // codition for item is selected. { //// set the cell color TableCell cell = item["SequencialNumber"]; cell.BackColor = Color.White; // set the row color item.BackColor = System.Drawing.Color.Red; } } RadGrid1.MasterTableView.AllowPaging = false; // if you are used pagging then set Allowpagging="true" here } } }I already update the button click event in my last post please replace your code with that code and let me know if any concern.
protected void Button1_Click(object sender, EventArgs e) { RadGrid1.MasterTableView.AllowPaging = false; RadGrid1.Skin = "Black"; RadGrid1.Rebind(); int Selectedcount = 0; foreach (GridDataItem item in RadGrid1.Items) { if (item.Selected) { Selectedcount++; item.BackColor = Color.Red; } } Button1.Text = "Selected :(" + Selectedcount.ToString() + ")" + " Total :(" + RadGrid1.Items.Count.ToString() + ")"; RadGrid1.MasterTableView.AllowPaging = true; RadGrid1.SelectedItemStyle.CssClass = "TextCss"; RadGrid1.Rebind(); }<style type="text/css"> .TextCss { background: red !important; } </style>for more information please see my last post.
Thanks,
Jayesh Goyani
What I need is allow the user to :
1.Select some Rows
2.Click on the button Process
3.After the click I want that those rows become in other color forever, even if the user change to another grid page, I want that those rows to keep the "processed" color.
Only if the user select those rows again and click on the other button(Unprocessed) i want that rows become with the default color.
Now what's happening is the user click the button processed and after that the user select the rows and those rows become red, but after the user select another page for example, and return to the first page, those rows are on the default color again...
Thanksa lot for your patient...
this code show every time selected item with applied style.
Solution 1:
protected void Button1_Click(object sender, EventArgs e) { RadGrid1.MasterTableView.AllowPaging = false; RadGrid1.Skin = "Black"; RadGrid1.Rebind(); int Selectedcount = 0; foreach (GridDataItem item in RadGrid1.Items) { if (item.Selected) { Selectedcount++; //item.BackColor = Color.Red; // comment this line } } Button1.Text = "Selected :(" + Selectedcount.ToString() + ")" + " Total :(" + RadGrid1.Items.Count.ToString() + ")"; RadGrid1.MasterTableView.AllowPaging = true; RadGrid1.SelectedItemStyle.CssClass = "TextCss"; RadGrid1.Rebind(); }// add this event in your gridprotected void RadGrid1_PreRender(object sender, EventArgs e) {RadGrid1.SelectedItemStyle.CssClass = "TextCss";
}this code show ONLY AFTER BUTTON CLICK selected item with applied style.
Solution 2:
.......................public bool _IsStyleApply { set { ViewState["IsStyleApply"] = value; } get { if (ViewState["IsStyleApply"] != null) { return Convert.ToBoolean(ViewState["IsStyleApply"]); } else { return false; } } } ..........................protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { _IsStyleApply = false; } }......................... protected void Button1_Click(object sender, EventArgs e) { RadGrid1.MasterTableView.AllowPaging = false; RadGrid1.Skin = "Black"; RadGrid1.Rebind(); int Selectedcount = 0; foreach (GridDataItem item in RadGrid1.Items) { if (item.Selected) { Selectedcount++; //item.BackColor = Color.Red; } } Button1.Text = "Selected :(" + Selectedcount.ToString() + ")" + " Total :(" + RadGrid1.Items.Count.ToString() + ")"; RadGrid1.MasterTableView.AllowPaging = true; // below line added recently _IsStyleApply = true; RadGrid1.Rebind(); }..................................... protected void RadGrid1_PreRender(object sender, EventArgs e) { if (_IsStyleApply) { RadGrid1.SelectedItemStyle.CssClass = "TextCss"; } }Let me know if any concern.
Thanks,
Jayesh Goyani
At this moment after I click the button when I select the rows, them become red, but if i change the grid page and go back to the first those rows are another time on the default color....
please send your latest code again.
and let me know want you want in this code.
let me know if any concern.
Thanks,
Jayesh Goyani
public partial class InvoicesScalingDefault : Microsoft.Practices.CompositeWeb.Web.UI.Page, IInvoicesScale { private InvoicesScalePresenter _presenter; public System.Collections.Generic.IList<Data.SapDocuments> SapDocuments { get; set; } protected void Page_Load(object sender, EventArgs e) { if (!this.IsPostBack) { this._presenter.OnViewInitialized(); _IsStyleApply = false; } this._presenter.OnViewLoaded(); } [CreateNew] public InvoicesScalePresenter Presenter { set { this._presenter = value; this._presenter.View = this; } } private void LoadData() { //Popular dados na Radlist SapDocumentsBO sapDocs = new SapDocumentsBO(); string user = Page.User.Identity.Name.Substring(Page.User.Identity.Name.IndexOf("\\") + 1); if ((user == "apsilva3") || (user == "scfreitas")) { this.SapDocuments = sapDocs.GetSapDocuments(); RadGrid1.DataSource = this.SapDocuments; } else { this.SapDocuments = sapDocs.GetSapDocumentsByUser(user); RadGrid1.DataSource = this.SapDocuments; } } protected void RadGrid1_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e) { LoadData(); } /// <summary> /// Export de todos os SequencialNumber da tabela para .csv /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void RadGrid1_ItemCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e) { if (e.CommandName == Telerik.Web.UI.RadGrid.ExportToCsvCommandName) { RadGrid1.MasterTableView.Columns.FindByUniqueName("SequencialNumber").Visible = true; RadGrid1.ExportSettings.IgnorePaging = true; int count = 0; foreach (GridColumn column in RadGrid1.Columns) { if (column.Visible) { if (count > 0) column.Visible = false; else count++; } } } } /// <summary> /// Método para formatar o sequencialNumber /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void RadGrid1_GridExporting(object sender, GridExportingArgs e) { e.ExportOutput = e.ExportOutput.Replace("\"\r\n\"", "\"\r\n\"'"); } public bool _IsStyleApply { set { ViewState["IsStyleApply"] = value; } get { if (ViewState["IsStyleApply"] != null) { return Convert.ToBoolean(ViewState["IsStyleApply"]); } else { return false; } } }
protected void Button1_Click(object sender, EventArgs e) { RadGrid1.MasterTableView.AllowPaging = false; RadGrid1.Skin = "Black"; RadGrid1.Rebind(); int Selectedcount = 0; foreach (GridDataItem item in RadGrid1.Items) { if (item.Selected) { Selectedcount++; //item.BackColor = Color.Red; } } Button1.Text = "Selected :(" + Selectedcount.ToString() + ")" + " Total :(" + RadGrid1.Items.Count.ToString() + ")"; RadGrid1.MasterTableView.AllowPaging = true; // below line added recently _IsStyleApply = true; RadGrid1.Rebind(); }..................................... protected void RadGrid1_PreRender(object sender, EventArgs e) { if (_IsStyleApply) { RadGrid1.SelectedItemStyle.CssClass = "TextCss"; } } //Here I want to select the rows that are select(Red) yet and change to the default color protected void RadButton2_Click(object sender, EventArgs e) { RadGrid1.MasterTableView.AllowPaging = false; RadGrid1.Skin = "Black"; RadGrid1.Rebind(); int Selectedcount = 0; foreach (GridDataItem item in RadGrid1.Items) { if (item.Selected) { Selectedcount++; //item.BackColor = Color.Red; // comment this line } } //Button1.Text = "Selected :(" + Selectedcount.ToString() + ")" + " Total :(" + RadGrid1.Items.Count.ToString() + ")"; RadGrid1.MasterTableView.AllowPaging = true; RadGrid1.SelectedItemStyle.CssClass = "TextCss"; RadGrid1.Rebind(); } } }My aspx file:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="InvoincesScale.aspx.cs" Inherits="iConnect.InvoicesScaling.Views.InvoicesScalingDefault" Title="Invoices Scale" MasterPageFile="~/Shared/Silver.master" %> <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %> <asp:Content ID="content" ContentPlaceHolderID="DefaultContent" runat="Server"> <script src="../Shared/js/jquery-1.6.2.min.js" type="text/javascript"></script> <script src="../Shared/js/jquery.tooltip.js" type="text/javascript"></script> <script type="text/javascript" src="../Silverlight.js"></script> <style type="text/css"> .RadGrid_Black .rgFilterBox { background-color: #454545 !important; } .TextCss { background: red !important; } </style> <h1 style="text-align: center;"> Invoices Scale</h1> <br /> <div> <telerik:RadGrid ID="RadGrid1" runat="server" GridLines="None" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" ViewStateMode="Disabled" Width="97%" enableajax="True" CssClass="productsGrid" CellSpacing="0" AllowFilteringByColumn="True" ShowFooter="True" Skin="Black" OnItemCommand="RadGrid1_ItemCommand" OnGridExporting="RadGrid1_GridExporting" OnNeedDataSource="RadGrid1_NeedDataSource" AllowMultiRowSelection="True" OnPreRender="RadGrid1_PreRender"> <PagerStyle Mode="NextPrevAndNumeric"></PagerStyle> <ClientSettings AllowColumnsReorder="True" ReorderColumnsOnClient="True"> <Selecting AllowRowSelect="True" /> </ClientSettings> <MasterTableView GridLines="None" Width="100%" ViewStateMode="Disabled" CommandItemSettings-ShowExportToCsvButton="True" CommandItemSettings-ShowAddNewRecordButton="false" CommandItemDisplay="Top"> <Columns> <telerik:GridBoundColumn DataField="SequencialNumber" HeaderText="SequencialNumber" UniqueName="SequencialNumber" SortExpression="SequencialNumber"> </telerik:GridBoundColumn> <telerik:GridBoundColumn DataField="Priorities.Priority" HeaderText="Priority" UniqueName="Priority" FilterControlAltText="Filter Priority column" SortExpression="Priority" DataType="System.Int32"> </telerik:GridBoundColumn> <telerik:GridBoundColumn DataField="Staging.Process" HeaderText="Staging" UniqueName="Process" SortExpression="Process" FilterControlAltText="Filter Process column"> </telerik:GridBoundColumn> <telerik:GridBoundColumn DataField="SupplierCode" HeaderText="SupplierCode" UniqueName="SupplierCode" SortExpression="SupplierCode" FilterControlAltText="Filter SupplierCode column"> </telerik:GridBoundColumn> <telerik:GridBoundColumn DataField="MessageStatus" HeaderText="MessageStatus" UniqueName="MessageStatus" SortExpression="MessageStatus" FilterControlAltText="Filter MessageStatus column"> </telerik:GridBoundColumn> <telerik:GridBoundColumn DataField="DocumentType" HeaderText="DocumentType" UniqueName="DocumentType" FilterControlAltText="Filter DocumentType column" SortExpression="DocumentType"> </telerik:GridBoundColumn> <telerik:GridDateTimeColumn UniqueName="InvoiceCreationDate" DataField="InvoiceCreationDate" HeaderText="InvoiceCreationDate" FilterControlAltText="Filter InvoiceCreationDate column" SortExpression="InvoiceCreationDate"> <FilterTemplate> <telerik:RadDatePicker ID="RadDatePicker1" runat="server"> </telerik:RadDatePicker> </FilterTemplate> </telerik:GridDateTimeColumn> <telerik:GridBoundColumn DataField="SupplierVatNumber" FilterControlAltText="Filter SupplierVatNumber column" HeaderText="SupplierVatNumber" SortExpression="SupplierVatNumber" UniqueName="SupplierVatNumber"> </telerik:GridBoundColumn> </Columns> <ExpandCollapseColumn Visible="False"> <HeaderStyle Width="19px"></HeaderStyle> </ExpandCollapseColumn> <RowIndicatorColumn Visible="False"> <HeaderStyle Width="20px" /> </RowIndicatorColumn> </MasterTableView> <FilterMenu EnableImageSprites="False"> </FilterMenu> <HeaderContextMenu CssClass="GridContextMenu GridContextMenu_Default"> </HeaderContextMenu> </telerik:RadGrid> <br /> <telerik:RadButton ID="RadButton1" runat="server" Text="Processed" Skin="Black" Width="100px" Height="50px" OnClick="RadButton1_Click"> </telerik:RadButton> <telerik:RadButton ID="RadButton2" runat="server" Text="Unprocessed" Skin="Black" Width="100px" Height="50px" OnClick="RadButton2_Click"> </telerik:RadButton> </div> <br /> <br /> <br /> <br /> <br /> </asp:Content> Now After I select the rows, when I click the button, the page loads and nothings happen....
If I click the button again then when I select the rows, them become red, but if i change the grid page and go back to the first those rows are another time on the default color....
What I need is allow the user to :
1.Select some Rows
2.Click on the button Process-->Rows Selected became Red,After the click I want that those rows become in other color forever, even if the user change to another grid page, I want that those rows to keep the "processed" color.
3.Allow the user to select the Red Rows and click on the other button(Unprocessed) i want that rows become with the default color.
Are you understanding? I want a button to change the color of the selected items onclick event and other button to to change the Reds Rows to the default color.....Like a process to mark and unmark rows of the grid..but I need that marks to stay visible if I change the grid page, or sort or filter items....
Thank you again
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="TelerikTest.Web.WebForm1" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"> <title></title> <style type="text/css"> .RadGrid_Black .rgFilterBox { background-color: #454545 !important; } .TextCss { background: red !important; } </style></head><body> <form id="form1" runat="server"> <div> <telerik:RadScriptManager ID="RadScriptManager1" runat="server"> </telerik:RadScriptManager> <telerik:RadGrid ID="RadGrid1" runat="server" GridLines="None" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" AllowFilteringByColumn="True" ShowFooter="True" Skin="Black" OnNeedDataSource="RadGrid1_NeedDataSource" AllowMultiRowSelection="True" OnPreRender="RadGrid1_PreRender" onitemcommand="RadGrid1_ItemCommand" onitemdatabound="RadGrid1_ItemDataBound"> <PagerStyle Mode="NextPrevAndNumeric"></PagerStyle> <ClientSettings AllowColumnsReorder="True" ReorderColumnsOnClient="True" EnablePostBackOnRowClick="true" > <Selecting AllowRowSelect="True" /> </ClientSettings> <MasterTableView DataKeyNames="ID"> <Columns> <telerik:GridBoundColumn DataField="ID" HeaderText="ID" UniqueName="ID" SortExpression="ID"> </telerik:GridBoundColumn> <telerik:GridBoundColumn DataField="Name" HeaderText="Name" UniqueName="Name" SortExpression="Name"> </telerik:GridBoundColumn> </Columns> </MasterTableView> </telerik:RadGrid> <br /> <telerik:RadButton ID="RadButton1" runat="server" Text="Processed" Skin="Black" Width="100px" Height="50px" OnClick="RadButton1_Click"> </telerik:RadButton> <telerik:RadButton ID="RadButton2" runat="server" Text="UNProcessed" Skin="Black" Width="100px" Height="50px" onclick="RadButton2_Click" > </telerik:RadButton> </div> </form></body></html>using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using Telerik.Web.UI;using System.Drawing;namespace TelerikTest.Web{ public partial class WebForm1 : System.Web.UI.Page { public bool _IsStyleApply { set { ViewState["IsStyleApply"] = value; } get { if (ViewState["IsStyleApply"] != null) { return Convert.ToBoolean(ViewState["IsStyleApply"]); } else { return false; } } } public string _SelectedID { set { ViewState["SelectedID"] = value; } get { if (ViewState["SelectedID"] != null) { return Convert.ToString(ViewState["SelectedID"]); } else { return ",0,"; } } } public string _AppliedSelectedID { set { ViewState["AppliedSelectedID"] = value; } get { if (ViewState["AppliedSelectedID"] != null) { return Convert.ToString(ViewState["AppliedSelectedID"]); } else { return string.Empty; } } } protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { _IsStyleApply = false; _SelectedID = ",0,"; _AppliedSelectedID = string.Empty; } } protected void RadButton1_Click(object sender, EventArgs e) { RadGrid1.MasterTableView.AllowPaging = false; //RadGrid1.Skin = "Black"; RadGrid1.Rebind(); int Selectedcount = 0; foreach (GridDataItem item in RadGrid1.Items) { if (item.Selected) { Selectedcount++; //item.BackColor = Color.Red; } } RadButton1.Text = "Selected :(" + Selectedcount.ToString() + ")" + " Total :(" + RadGrid1.Items.Count.ToString() + ")"; RadGrid1.MasterTableView.AllowPaging = true; // below line added recently _IsStyleApply = true; _AppliedSelectedID = _SelectedID; RadGrid1.Rebind(); } protected void RadGrid1_PreRender(object sender, EventArgs e) { if (_IsStyleApply) { //RadGrid1.SelectedItemStyle.CssClass = "TextCss"; foreach (GridDataItem item in RadGrid1.Items) { if (_AppliedSelectedID.Contains("," + Convert.ToInt32(item.GetDataKeyValue("ID")).ToString() + ",")) { item.CssClass = "TextCss"; } } } } protected void RadGrid1_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e) { dynamic data = new[] { new { ID = 1, Name ="Name1"}, new { ID = 2, Name = "Name2"}, new { ID = 3, Name = "Name3"}, new { ID = 4, Name = "Name4"}, new { ID = 5, Name = "Name5"}, new { ID = 6, Name ="Name6"}, new { ID = 7, Name = "Name7"}, new { ID = 8, Name = "Name8"}, new { ID = 9, Name = "Name9"}, new { ID = 10, Name = "Name10"}, new { ID = 11, Name ="Name11"}, new { ID = 12, Name = "Name12"}, new { ID = 13, Name = "Name13"}, new { ID = 14, Name = "Name14"}, new { ID = 15, Name = "Name15"} }; RadGrid1.DataSource = data; } protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e) { if (e.CommandName == "RowClick") { foreach (GridDataItem item in RadGrid1.Items) { if (item.Selected) _SelectedID = _SelectedID + Convert.ToInt32(item.GetDataKeyValue("ID")).ToString() + ","; else _SelectedID = _SelectedID.Replace( Convert.ToInt32(item.GetDataKeyValue("ID")).ToString() + ",", ""); } } } protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) { if (e.Item is GridDataItem) { GridDataItem item = e.Item as GridDataItem; if (_SelectedID.Contains("," + Convert.ToInt32(item.GetDataKeyValue("ID")).ToString() + ",")) { item.Selected = true; } } } protected void RadButton2_Click(object sender, EventArgs e) { RadGrid1.MasterTableView.AllowPaging = false; //RadGrid1.Skin = "Black"; RadGrid1.Rebind(); int Selectedcount = 0; foreach (GridDataItem item in RadGrid1.Items) { if (item.Selected) { _AppliedSelectedID = _AppliedSelectedID.Replace(Convert.ToInt32(item.GetDataKeyValue("ID")).ToString() + ",", ""); } } RadButton2.Text = "Selected :(" + Selectedcount.ToString() + ")" + " Total :(" + RadGrid1.Items.Count.ToString() + ")"; RadGrid1.MasterTableView.AllowPaging = true; RadGrid1.Rebind(); } }}Let me know if any concern.
Thanks,
Jayesh Goyani
protected void RadGrid1_ItemCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e) { if (e.CommandName == Telerik.Web.UI.RadGrid.ExportToCsvCommandName) { RadGrid1.MasterTableView.Columns.FindByUniqueName("SequencialNumber").Visible = true; RadGrid1.ExportSettings.IgnorePaging = true; int count = 0; foreach (GridColumn column in RadGrid1.Columns) { if (column.Visible) { if (count > 0) column.Visible = false; else count++; } } } if (e.CommandName == "RowClick") { foreach (GridDataItem item in RadGrid1.Items) { if (item.Selected) _SelectedID = _SelectedID + Convert.ToInt32(item.GetDataKeyValue("ID")).ToString() + ","; else _SelectedID = _SelectedID.Replace(Convert.ToInt32(item.GetDataKeyValue("ID")).ToString() + ",", ""); } } }yes you can.
thanks,
Jayesh Goyani
At this moment when I run the page, all rows appear selected but with the default color(not a problem).
When I select um row and click the button Processed....ALL ROWS become red.......not only the selected but all of them..
The unprocessed button are working fine, after click all rows return to default color....
I think the problem is th "ID" .....what is my "ID"?? Is any column uniqueName??
Thats my code:
public bool _IsStyleApply { set { ViewState["IsStyleApply"] = value; } get { if (ViewState["IsStyleApply"] != null) { return Convert.ToBoolean(ViewState["IsStyleApply"]); } else { return false; } } } public string _SelectedID { set { ViewState["SelectedID"] = value; } get { if (ViewState["SelectedID"] != null) { return Convert.ToString(ViewState["SelectedID"]); } else { return ",0,"; } } } public string _AppliedSelectedID { set { ViewState["AppliedSelectedID"] = value; } get { if (ViewState["AppliedSelectedID"] != null) { return Convert.ToString(ViewState["AppliedSelectedID"]); } else { return string.Empty; } } } public System.Collections.Generic.IList<Data.SapDocuments> SapDocuments { get; set; } protected void Page_Load(object sender, EventArgs e) { if (!this.IsPostBack) { this._presenter.OnViewInitialized(); _IsStyleApply = false; _SelectedID = ",0,"; _AppliedSelectedID = string.Empty; } this._presenter.OnViewLoaded(); } [CreateNew] public InvoicesScalePresenter Presenter { set { this._presenter = value; this._presenter.View = this; } } private void LoadData() { //Popular dados na Radlist SapDocumentsBO sapDocs = new SapDocumentsBO(); string user = Page.User.Identity.Name.Substring(Page.User.Identity.Name.IndexOf("\\") + 1); if ((user == "apsilva3") || (user == "scfreitas")) { this.SapDocuments = sapDocs.GetSapDocuments(); RadGrid1.DataSource = this.SapDocuments; } else { this.SapDocuments = sapDocs.GetSapDocumentsByUser(user); RadGrid1.DataSource = this.SapDocuments; } } protected void RadButton1_Click(object sender, EventArgs e) { RadGrid1.MasterTableView.AllowPaging = false; //RadGrid1.Skin = "Black"; RadGrid1.Rebind(); int Selectedcount = 0; foreach (GridDataItem item in RadGrid1.Items) { if (item.Selected) { Selectedcount++; //item.BackColor = Color.Red; } } RadButton1.Text = "Selected :(" + Selectedcount.ToString() + ")" + " Total :(" + RadGrid1.Items.Count.ToString() + ")"; RadGrid1.MasterTableView.AllowPaging = true; // below line added recently _IsStyleApply = true; _AppliedSelectedID = _SelectedID; RadGrid1.Rebind(); } protected void RadButton2_Click(object sender, EventArgs e) { RadGrid1.MasterTableView.AllowPaging = false; //RadGrid1.Skin = "Black"; RadGrid1.Rebind(); int Selectedcount = 0; foreach (GridDataItem item in RadGrid1.Items) { if (item.Selected) { _AppliedSelectedID = _AppliedSelectedID.Replace(Convert.ToInt32(item.GetDataKeyValue("ID")).ToString() + ",", ""); } } RadButton2.Text = "Selected :(" + Selectedcount.ToString() + ")" + " Total :(" + RadGrid1.Items.Count.ToString() + ")"; RadGrid1.MasterTableView.AllowPaging = true; RadGrid1.Rebind(); } protected void RadGrid1_PreRender(object sender, EventArgs e) { if (_IsStyleApply) { //RadGrid1.SelectedItemStyle.CssClass = "TextCss"; foreach (GridDataItem item in RadGrid1.Items) { if (_AppliedSelectedID.Contains("," + Convert.ToInt32(item.GetDataKeyValue("ID")).ToString() + ",")) { item.CssClass = "TextCss"; } } } } protected void RadGrid1_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e) { LoadData(); } /// <summary> /// Export de todos os SequencialNumber da tabela para .csv /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e) { if (e.CommandName == "RowClick") { foreach (GridDataItem item in RadGrid1.Items) { if (item.Selected) _SelectedID = _SelectedID + Convert.ToInt32(item.GetDataKeyValue("ID")).ToString() + ","; else _SelectedID = _SelectedID.Replace(Convert.ToInt32(item.GetDataKeyValue("ID")).ToString() + ",", ""); } } if (e.CommandName == Telerik.Web.UI.RadGrid.ExportToCsvCommandName) { RadGrid1.MasterTableView.Columns.FindByUniqueName("SequencialNumber").Visible = true; RadGrid1.ExportSettings.IgnorePaging = true; int count = 0; foreach (GridColumn column in RadGrid1.Columns) { if (column.Visible) { if (count > 0) column.Visible = false; else count++; } } } } /// <summary> /// Método para formatar o sequencialNumber /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void RadGrid1_GridExporting(object sender, GridExportingArgs e) { e.ExportOutput = e.ExportOutput.Replace("\"\r\n\"", "\"\r\n\"'"); } protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) { if (e.Item is GridDataItem) { GridDataItem item = e.Item as GridDataItem; if (_SelectedID.Contains("," + Convert.ToInt32(item.GetDataKeyValue("ID")).ToString() + ",")) { item.Selected = true; } } }ID is the DataKeyNames.
<MasterTableView DataKeyNames="ID">Please create one page and copy my all code in this page and then check and let me know its working or not.
Thanks,
Jayesh Goyani
if
(_SelectedID.Contains("," + Convert.ToInt32(item.GetDataKeyValue("SequencialNumber")).ToString() + ","))
----> Value was either too large or too small for an Int32.
Can i select another column item as my DatakeyvaluE??Or i need to deal with this??
I think after that I'll get it...please forgive me...it's urgent
On my page the problem is that conversion i've mentioned above...Can you please explain to me how to deal with that?
I've tried replacin to the Convert.ToInt64 and after I select a item and click the button nothings happen..
However I note that on your page if I select one row and mark them, if then i select another row and click the button...the first selection disappears.....Can you notice that?
How Can I avoid that?
if
(_SelectedID.Contains("," + Convert.ToInt32(item.GetDataKeyValue("SequencialNumber")).ToString() + ","))
----> Value was either too large or too small for an Int32.
Can i select another column item as my DatakeyvaluE??Or i need to deal with this??
I think after that I'll get it...please forgive me...it's urgent
...............................
Yes you can take any other column as a DataKeyName...
its not needed to take only Integer value.
DataKeyNames="ID,Names,Address,Photo".....
Note : but as per your requirement Take any Unique Field.
Thanks,
Jayesh Goyani
However I note that on your page if I select one row and mark them, if then i select another row and click the button...the first selection disappears.....Can you notice that?
try to select with CTRL key.
Thanks,
Jayesh Goyani
There is other way also to achieve your requirement.(with asp:CheckBox inside GridTempleteColumn)
http://www.telerik.com/community/forums/aspnet-ajax/grid/select-multiple-colums-from-a-radgrid-with-paging-enabled.aspx
Thanks,
Jayesh Goyani
If you don't mind, can you tell me how can I get the rows that are at red?? which is the property?
The second button(Unprocessed) is not counting the Processed and updating the text because there are none "Selected" so the counting appears like "Processed (0) Total(300) " when you can see rows at red...can i get those rows to count?
protected void RadButton2_Click(object sender, EventArgs e) {int TotalCount = 0; RadGrid1.MasterTableView.AllowPaging = false; //RadGrid1.Skin = "Black"; RadGrid1.Rebind(); int Selectedcount = 0; foreach (GridDataItem item in RadGrid1.Items) { if (AppliedSelectedID.Contains("," + Convert.ToInt32(item.GetDataKeyValue("ID")).ToString() + ",")) { TotalCount ++; } if (item.Selected) { _AppliedSelectedID = _AppliedSelectedID.Replace(Convert.ToInt32(item.GetDataKeyValue("ID")).ToString() + ",", ""); } } RadButton2.Text = "Selected :(" + Selectedcount.ToString() + ")" + " Total :(" + TotalCount .ToString() + ")"; RadGrid1.MasterTableView.AllowPaging = true; RadGrid1.Rebind(); }Let me know if any concern.
Thanks,
Jayesh Goyani
Thanks a lot for your support