This is a migrated thread and some comments may be shown as answers.

RadGrid SelectedItems change color

32 Answers 589 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ricardo
Top achievements
Rank 1
Ricardo asked on 10 Aug 2011, 12:27 PM
Hello people,

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

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 10 Aug 2011, 12:38 PM
Hello,

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
0
Ricardo
Top achievements
Rank 1
answered on 10 Aug 2011, 12:42 PM
Thanks Jayesh,
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?
0
Jayesh Goyani
Top achievements
Rank 2
answered on 10 Aug 2011, 01:39 PM
Hello,

// if you are used pagging then set Allowpagging="False" here
 
 
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["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" here

you can get directly   SelectedRowCount  = RadGrid1.SelectedItems.count;

let me know if any concern.

Thanks,
Jayesh Goyani
0
Ricardo
Top achievements
Rank 1
answered on 10 Aug 2011, 02:46 PM
Thanks a lot, one last question on your code I'm using paging...Do I need to set pagin false on your comments and then set true??
Why?»
0
Ricardo
Top achievements
Rank 1
answered on 10 Aug 2011, 04:26 PM
Sorry Jayesh at this moment i put the code on event click button, and nothings happen...What is missing?
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;
0
Ricardo
Top achievements
Rank 1
answered on 10 Aug 2011, 04:33 PM
I think i have to change TableCell to Table Row...but how I do this??

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
0
Ricardo
Top achievements
Rank 1
answered on 10 Aug 2011, 04:42 PM

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 ++;
            }
0
Ricardo
Top achievements
Rank 1
answered on 10 Aug 2011, 04:52 PM
Sorry another question...When i click the other button how i can change color to the Default(Skin Blak) color of the Grid...??
0
Ricardo
Top achievements
Rank 1
answered on 10 Aug 2011, 06:09 PM
My Code Behind is :
  
        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
        }
    }
}
0
Jayesh Goyani
Top achievements
Rank 2
answered on 10 Aug 2011, 06:35 PM
Hello Ricardo,

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">
<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
0
Ricardo
Top achievements
Rank 1
answered on 10 Aug 2011, 06:52 PM
At this moment I have this code....but nothings happens after the click....Can you help me??
        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
        }
    }
}
0
Jayesh Goyani
Top achievements
Rank 2
answered on 10 Aug 2011, 06:56 PM
Hello,

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
0
Ricardo
Top achievements
Rank 1
answered on 10 Aug 2011, 07:13 PM
Hello again Jayesh, after use your code, the goal was not achieve....

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...
0
Jayesh Goyani
Top achievements
Rank 2
answered on 10 Aug 2011, 07:26 PM
Hello,

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 grid
protected 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
0
Ricardo
Top achievements
Rank 1
answered on 11 Aug 2011, 09:27 AM
Hello Jayesh I tried your solution 2 and it's not working....After I select the rows when I click the button, the page loads and nothings happen....

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....
0
Jayesh Goyani
Top achievements
Rank 2
answered on 11 Aug 2011, 09:38 AM
Hello,

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
0
Ricardo
Top achievements
Rank 1
answered on 11 Aug 2011, 10:10 AM
Hello Jayesh this is my latest 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();
                _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....

 


0
Ricardo
Top achievements
Rank 1
answered on 11 Aug 2011, 10:17 AM
Jayesh please note that I just updated my code on the last post..

Thank you again
0
Accepted
Jayesh Goyani
Top achievements
Rank 2
answered on 11 Aug 2011, 01:15 PM
Hello,

<%@ 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">
<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
0
Ricardo
Top achievements
Rank 1
answered on 11 Aug 2011, 03:23 PM
Hello Jayesh, I'm trying your code right now...But I had a doubt....I already have an OnItemComand event...can i put the code like this:
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() + ",", "");
                }
            }
        }
0
Jayesh Goyani
Top achievements
Rank 2
answered on 11 Aug 2011, 03:31 PM
Hello,

yes you can.

thanks,
Jayesh Goyani
0
Ricardo
Top achievements
Rank 1
answered on 11 Aug 2011, 03:37 PM
Hello Jayesh i'm trying your code and at this moment I are almost there...
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;
                }
            }
        }
0
Jayesh Goyani
Top achievements
Rank 2
answered on 11 Aug 2011, 03:56 PM
Hello,

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
0
Ricardo
Top achievements
Rank 1
answered on 11 Aug 2011, 04:08 PM
Hello thanks a lot for your help...At this moment I get an error on my event RadGrid1_ItemDataBound

 

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
0
Ricardo
Top achievements
Rank 1
answered on 11 Aug 2011, 04:22 PM
I've tried your code on a different page and it's working....

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..
0
Ricardo
Top achievements
Rank 1
answered on 11 Aug 2011, 04:55 PM
Hello Jayesh at this moment i note that some changes were missing on my code...After that My grid is now exactly as your demo...

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?
0
Jayesh Goyani
Top achievements
Rank 2
answered on 11 Aug 2011, 05:23 PM
Hello,

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
0
Accepted
Jayesh Goyani
Top achievements
Rank 2
answered on 11 Aug 2011, 05:30 PM
Hello,


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
0
Jayesh Goyani
Top achievements
Rank 2
answered on 11 Aug 2011, 05:34 PM
Hello,

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
0
Ricardo
Top achievements
Rank 1
answered on 11 Aug 2011, 06:39 PM
Thanks a lot Jayesh for your patient and support..

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?
0
Jayesh Goyani
Top achievements
Rank 2
answered on 12 Aug 2011, 09:36 AM
Hello,

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
0
Ricardo
Top achievements
Rank 1
answered on 12 Aug 2011, 09:53 AM
Tags
Grid
Asked by
Ricardo
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Ricardo
Top achievements
Rank 1
Share this question
or