Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
140
Not able to have rows selected on "..DataFiltered" function
posted

<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true"
    CodeBehind="tst.aspx.cs" Inherits="ASSET.Maintain.tst" %>

<%@ Register Assembly="Infragistics4.Web.v13.1, Version=13.1.20131.1012, Culture=neutral, PublicKeyToken=7dd5c3163f2cd0cb"
    Namespace="Infragistics.Web.UI.GridControls" TagPrefix="ig" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <ig:WebDataGrid ID="WebDataGrid1" runat="server" Height="350px" Width="400px"
        AutoGenerateColumns="False" DataKeyFields="ControlsId"
        ondatafiltered="WebDataGrid1_DataFiltered"
        ondatafiltering="WebDataGrid1_DataFiltering"
        onrowselectionchanged="WebDataGrid1_RowSelectionChanged">
        <Columns>
            <ig:BoundDataField DataFieldName="CONTROLSID" Key="ControlsId" DataType="System.Int32">
                <Header Text="Control ID" />
            </ig:BoundDataField>
            <ig:BoundDataField DataFieldName="SHORTDESCRIPTION" Key="SHORTDESCRIPTION" DataType="System.String">
                <Header Text="Short Description" />
            </ig:BoundDataField>
        </Columns>
        <Behaviors>
            <ig:Selection CellClickAction="Row" EnableCrossPageSelection="True"
                RowSelectType="Multiple" CellSelectType="Multiple">
            </ig:Selection>
            <ig:RowSelectors>
            </ig:RowSelectors>
            <ig:VirtualScrolling>
            </ig:VirtualScrolling>
            <ig:Filtering>
                <ColumnSettings>
                    <ig:ColumnFilteringSetting ColumnKey="CONTROLSID" />
                </ColumnSettings>
            </ig:Filtering>
        </Behaviors>
    </ig:WebDataGrid>
</asp:Content>

---------------------------------------------------------

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;
using DTO;
using Infragistics.Web.UI.GridControls;

namespace ASSET.Maintain
{
    public partial class tst : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {


            ControlsBLL oControlsBLL = new ControlsBLL();
            ControlsDTO oControlsDTO = new ControlsDTO();

            WebDataGrid1.DataSource = oControlsBLL.Select(oControlsDTO);
            WebDataGrid1.DataBind();

        }

        protected void WebDataGrid1_RowSelectionChanged(object sender, Infragistics.Web.UI.GridControls.SelectedRowEventArgs e)
        {
            //IList<int> ids = new List<int>();
            //int id = 0;
            //int index = 0;

            //foreach (GridRecord row in e.CurrentSelectedRows)
            //{
            //    if (row == null)
            //    {
            //        IDPair pair = e.CurrentSelectedRows.GetIDPair(index);
            //        id = Convert.ToInt32(pair.Key[0]);

            //    }
            //    else
            //    {
            //        id = Convert.ToInt32(row.DataKey[0]);
            //    }

            //    if (!ids.Contains(id))
            //    {
            //        ids.Add(id);
            //    }
            //    index++;
            //}


            //Session["SELECTED_CONTROLS"] = ids;
        }

        protected void WebDataGrid1_DataFiltered(object sender, FilteredEventArgs e)
        {
            if (Session["SELECTED_CONTROLS"] != null)
            {
               
                List<int> lstControlsIDs = new List<int>();
                lstControlsIDs = (List<int>)Session["SELECTED_CONTROLS"];

                SelectedRowCollection selectedRow = this.WebDataGrid1.Behaviors.Selection.SelectedRows;

                foreach (int id in lstControlsIDs)
                {

                    foreach (GridRecord gr in WebDataGrid1.Rows)
                    {
                        if (gr.Items[0].Row.Items[0].Value.ToString() == id.ToString())
                        {
                            selectedRow.Add(gr);
                            //selectedRow.Add(WebDataGrid1.Behaviors.Selection.SelectedRows.GetIDPair(index));           
                        }
                    }
                }

               
            }
        }

        protected void WebDataGrid1_DataFiltering(object sender, FilteringEventArgs e)
        {
            IList<int> ids = new List<int>();
            int id = 0;
            int index = 0;
           
            foreach (GridRecord row in WebDataGrid1.Behaviors.Selection.SelectedRows)
            {
                if (row == null)
                {
                    IDPair pair = WebDataGrid1.Behaviors.Selection.SelectedRows.GetIDPair(index);
                    id = Convert.ToInt32(pair.Key[0]);

                }
                else
                {
                    id = Convert.ToInt32(row.DataKey[0]);
                }

                if (!ids.Contains(id))
                {
                    ids.Add(id);
                }
                index++;
            }


            Session["SELECTED_CONTROLS"] = ids;
        }


    }
}

 

-------------------------------

For example I select rows number 10 and 20, and then I want to filter the grid. The results of this filtering contain the row 20, so I want to have that row shown as selected, the same when I clean the filter and want to have everthing listed again, I want those two rows appear as selected I've got a SESSION variable which I'm filling with the selected rows in the WebDataGrid1_DataFiltering function, so when it applies the filter and goes to the WebDataGrid1_DataFiltered I will loop through the grid and select the ones that in the SESSION variable.

My code reaches the "selectedRod.Add(gr)" line, but nothing seems to happen when the page is displayed. I've really run out of ideas...I've been with this for 4 days :S Please help me!!! Thanks Diego