Sorting template column, which has dynamic header text

9 posts, 0 answers
  1. Jimmy Vithalani
    Jimmy Vithalani avatar
    22 posts
    Member since:
    Mar 2010

    Posted 31 May 2010 Link to this post

    Hey All,

    I have a RadGrid with template columns where I have checkboxes and textboxes. I want to provide sorting on these columns. The problem these columns have Dynamic header text, returned from function. According to some of the threads I read, Dynamic Headertext prevents sorting.

    I tried

    1.  <HeaderText> <% GetHeaderText("Column1")  %></HeaderText>

    2. On ItemCreated event, if item is HeaderItem, set item["Column1"].Text = GetHeaderText("Column1")

    Can I perform sorting on a template column which has dynamic header text?

    Thanks.
    Jimmy.
  2. Jimmy Vithalani
    Jimmy Vithalani avatar
    22 posts
    Member since:
    Mar 2010

    Posted 31 May 2010 Link to this post

    After this, I tried one more thing which I found here: http://www.telerik.com/help/aspnet-ajax/grdlocalizationforgridheaders.html

    if (e.Item is GridHeaderItem)
                {
                    GridHeaderItem headerItem = e.Item as GridHeaderItem;
                    if (headerItem["Name"].Controls.Count > 0 && headerItem["Name"].Controls[0] is LinkButton)
                    {
                        ((LinkButton)headerItem["Name"].Controls[0]).Text = GetWebString("Name");
                    }
    }

    Now I can see hand cursor on header text hover, and when I click it acts like it is sorting but it is not sorting the data.
    I have defined SortExpression = "Name", where name is my column name.

    Thanks.
    Jimmy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Pavlina
    Admin
    Pavlina avatar
    6084 posts

    Posted 31 May 2010 Link to this post

    Hello Jimmy,

    Could you please confirm that you are not binding the RadGrid control through simple data-binding calling DataBind()?

    Kind regards,
    Pavlina
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  5. Jimmy Vithalani
    Jimmy Vithalani avatar
    22 posts
    Member since:
    Mar 2010

    Posted 31 May 2010 Link to this post

    Hi Pavlina ,

    I did not get your question properly but, I am assigning a List of Custom Objects to DataSource of RadGrid on NeedDataSource to bind it.

    Thanks.
    Jimmy.
  6. Pavlina
    Admin
    Pavlina avatar
    6084 posts

    Posted 31 May 2010 Link to this post

    Hello Jimmy,

    It would be great if you could send us a sample project illustrating the described behavior. Thus I could debug it locally and investigate the issue in depth, so I could provide a proper solution.

    Thank you for your cooperation in advance.

    Greetings,
    Pavlina
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  7. Jimmy Vithalani
    Jimmy Vithalani avatar
    22 posts
    Member since:
    Mar 2010

    Posted 31 May 2010 Link to this post

    Hello Pavlina,

    Here is my code...

    ASPX:

    <telerik:RadGrid ID="grid" runat="server" Skin="Office2007" Width="90%" AllowSorting="true" 
                OnNeedDataSource="grid_NeedDataSource" AutoGenerateColumns="false"
                <MasterTableView> 
                    <Columns> 
                        <telerik:GridTemplateColumn UniqueName="Name" AllowFiltering="false" Groupable="false" 
                            SortExpression="Name"
                            <HeaderTemplate> 
                                <%# GetHeaderText() %> 
                            </HeaderTemplate> 
                            <HeaderStyle HorizontalAlign="Center" /> 
                            <ItemStyle HorizontalAlign="Center" /> 
                            <ItemTemplate> 
                                <asp:TextBox ID="txtName" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "Name")%>' 
                                    Width="50px"></asp:TextBox> 
                            </ItemTemplate> 
                        </telerik:GridTemplateColumn> 
                    </Columns> 
                </MasterTableView> 
            </telerik:RadGrid> 


    C#:


    public partial class WebForm1 : System.Web.UI.Page 
        { 
            protected void Page_Load(object sender, EventArgs e) 
            { 
                 
            } 
            protected void grid_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e) 
            { 
                //get List of person object and assign to data source 
                grid.DataSource = GetPersons(); 
            } 
            private List<Person> GetPersons() 
            { 
                List<Person> persons = new List<Person>(); 
                Person p = new Person("Pavlina"); 
                persons.Add(p); 
                p = new Person("Jimmy"); 
                persons.Add(p); 
                p = new Person("Telerik"); 
                persons.Add(p); 
     
                return persons; 
            } 
            public String GetHeaderText() 
            { 
                //header text as some logic to retrive 
                return "Name"
            } 
        } 
     
         
        class Person 
        { 
            public String Name 
            { 
                get
                set
            } 
            public Person(String name) 
            { 
                Name = name; 
            } 
        } 


    Thanks.
    Jimmy.

  8. Pavlina
    Admin
    Pavlina avatar
    6084 posts

    Posted 02 Jun 2010 Link to this post

    Hello Jimmy,

    Attached to this message is a modified application which handles the desired functionality. Please examine it and let me know if other questions or problems arise.

    Sincerely yours,
    Pavlina
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  9. Developer
    Developer avatar
    16 posts
    Member since:
    Jun 2009

    Posted 23 Jun 2010 Link to this post

    Thanks Pavlina, it helped me.

    Regards.
  10. Deepak
    Deepak avatar
    1 posts
    Member since:
    Feb 2015

    Posted 05 May in reply to Developer Link to this post

    Can you please help me.. I am not able to perform sorting ....

    <cc2:GridView ID="gvSchedule" runat="server" EnableEmbeddedSkins="false" ShowGroupPanel="false" EnableViewState="false" PagerStyle-AlwaysVisible="true"
                                                                                            AllowPaging="True" AllowSorting="True" PageSize="10" GroupingEnabled="false" CurrentTheme='<%#TEMS.TEMSSecurity.UserSkin%>' Width="100%">
                                                                                            <exportsettings ignorepaging="True" openinnewwindow="true" exportonlydata="true">
                                            </exportsettings>
                                                                                            <clientsettings>
                                                <Scrolling AllowScroll="true" UseStaticHeaders="true" SaveScrollPosition="True" />
                                                <Resizing AllowColumnResize="true" AllowResizeToFit="false" ResizeGridOnColumnResize="false"
                                                    ClipCellContentOnResize="false" />
                                            </clientsettings>
                                                                                            <mastertableview tablelayout="Fixed" name="master" width="100%">
                                                <HeaderStyle Wrap="true" HorizontalAlign="Center" VerticalAlign="Middle" />
                                                <ItemStyle Wrap="true" />
                                                <CommandItemSettings ShowExportToExcelButton="true" ShowExportToPdfButton="true" ShowExportToCsvButton="true" />
                                                <Columns>
                                                    <telerik:GridTemplateColumn AllowFiltering="false" AllowSorting="false" Exportable="false" UniqueName="Select" HeaderStyle-HorizontalAlign="Center"
                                                        ItemStyle-HorizontalAlign="Center" Resizable="false" Reorderable="false" HeaderStyle-Width="30px">
                                                        <HeaderTemplate>
                                                            <input type="checkbox" id="checkAll" runat="server" name="checkAll" />
                                                        </HeaderTemplate>
                                                        <ItemTemplate>
                                                            <input id="chkItem" type="checkbox" value='<%#Container.DataItem("SCD_ID")%>'
                                                                name="chkItem" runat="server" class="checkBoxesToCheck" onclick="GetCheckedRowsCount(this);" />
                                                        </ItemTemplate>
                                                    </telerik:GridTemplateColumn>
                                                </Columns>
                                            </mastertableview>
                                                                                        </cc2:GridView>

     

    ASPX.VB

     

    Imports MZKObj
    Imports MZKObj.MZKObj
    Imports System
    Imports MazikUSA.Web.UI.WebControls
    Imports System.Threading
    Imports MZKObj.MZKObj.CustomPages
    Imports MZKObj.MZKObj.Security
    Imports MZKObj.MZKObj.School
    Imports Telerik.Web.UI
    Imports System.IO
    Imports System.Web.UI
    Imports System.Globalization

    Public Class MassEditSCDates
        Inherits BasePage
        Private _DS As New DataSet
        Private _Filter As String = String.Empty
        Private EBOFilterOBJ As MZKForm.MZKErrorBuilder
    #Region "Enum"
        Public Enum ContentTypes As Integer
            textBox = 1
            dropDownList = 2
            dataDefinition = 3
            [date] = 4
            checkBox = 5
            hidden = 6
            label = 7
            changeableLabel = 8
            Combobox = 9
            htmlcheckbox = 10
        End Enum
    #End Region

    #Region "Private members"
        Const _PrimaryKey As String = "SCD_ID"
        Private Const _ddlSelectItem As String = "(Select)"
        Private Property ctrlScheduleCalendarDatesGrid As Object
        Private _mblnRegisterStartupScript As Boolean = True
        Private _mblnSelectAllCal As Boolean = False
        Private Const l_strInfoMessage As String = ""
    #End Region
    #Region "Properties"
        Public Property RegisterStartupScripts() As Boolean
            Get
                Return _mblnRegisterStartupScript
            End Get
            Set(ByVal value As Boolean)
                _mblnRegisterStartupScript = value
            End Set
        End Property

        Public Property SelectAllCal() As Boolean
            Get
                Return _mblnSelectAllCal
            End Get
            Set(ByVal value As Boolean)
                _mblnSelectAllCal = value
            End Set
        End Property
        Protected Property SelectedFields() As ArrayList
            Get
                Dim al As ArrayList
                If Not ViewState.Item("SelectedFields") Is Nothing Then
                    al = ViewState.Item("SelectedFields")
                End If
                Return al
            End Get
            Set(ByVal value As ArrayList)
                ViewState.Item("SelectedFields") = value
            End Set
        End Property
        Protected Property SelectedSystemFieldsString() As String
            Get
                Dim strSelectedSystemFieldsString As String
                If Not ViewState.Item("SelectedSystemFieldsString") Is Nothing Then
                    strSelectedSystemFieldsString = ViewState.Item("SelectedSystemFieldsString")
                Else
                    strSelectedSystemFieldsString = ""
                End If
                Return strSelectedSystemFieldsString
            End Get
            Set(ByVal value As String)
                ViewState.Item("SelectedSystemFieldsString") = value
            End Set
        End Property
        Protected Property SelectedUDFieldsString() As String
            Get
                Dim strSelectedUDFieldsString As String
                If Not ViewState.Item("SelectedUDFieldsString") Is Nothing Then
                    strSelectedUDFieldsString = ViewState.Item("SelectedUDFieldsString")
                Else
                    strSelectedUDFieldsString = ""
                End If
                Return strSelectedUDFieldsString
            End Get
            Set(ByVal value As String)
                ViewState.Item("SelectedUDFieldsString") = value
            End Set
        End Property
        Protected Property DataGridColumns() As DataTable
            Get
                Dim dt As DataTable
                If Not ViewState.Item("DataGridColumns") Is Nothing Then
                    dt = ViewState.Item("DataGridColumns")
                Else
                    dt = Nothing
                End If
                Return dt
            End Get
            Set(ByVal value As DataTable)
                ViewState.Item("DataGridColumns") = value
            End Set
        End Property

        Protected Property DataGridContent() As DataTable
            Get
                Dim dt As DataTable
                If Not ViewState.Item("DataGridContent") Is Nothing Then
                    dt = ViewState.Item("DataGridContent")
                Else
                    dt = Nothing
                End If
                Return dt
            End Get
            Set(ByVal value As DataTable)
                ViewState.Item("DataGridContent") = value
            End Set
        End Property
        Protected Property RecordCount() As String
            Get
                Dim intRecordCount As String
                If Not ViewState.Item("RecordCount") Is Nothing Then
                    intRecordCount = ViewState.Item("RecordCount")
                Else
                    intRecordCount = 0
                End If
                Return intRecordCount
            End Get
            Set(ByVal value As String)
                ViewState.Item("RecordCount") = value
            End Set
        End Property
        Public Property Filter() As String
            Get
                _Filter = GetFilterString()
                Return _Filter
            End Get
            Set(ByVal value As String)
                _Filter = value
            End Set
        End Property
        Protected Property PageIndex() As String
            Get
                Dim index As String = ""
                If Not ViewState.Item("PageIndex") Is Nothing Then
                    index = ViewState.Item("PageIndex")
                End If
                Return index
            End Get
            Set(ByVal value As String)
                ViewState.Item("PageIndex") = value
            End Set
        End Property
    #End Region

    #Region "Page Events"

        Private Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
            If DataGridColumns Is Nothing Then
                RetrieveSCDFields()
            End If
            If Not IsPostBack Then
                BindEditableFieldsCheckList()
            End If
            CreateDataGridColumns()
        End Sub

        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            If TEMSSecurity.IsPrivilegeAssigned(Privileges.AddSchedulingCalendar) Then
                If Not Page.IsPostBack Then
                    InitializeDefaultParams()
                End If
                LoadGridSettings(gvSchedule, "gvSchedule", Portals.SISAddEditCalendarHolidays)
                If Not Page.IsPostBack Then
                    ShowPageDirection(Portals.SISDistrictSchedulingCalendar, cntInfoPanelHelp, l_strInfoMessage)
                    FlyoutItems()
                    FillConfigurationGroup()
                    FillScheduleCalendarDDL()
                End If
                If RegisterStartupScripts Then
                    RegisterScripts()
                End If
            Else
                NavigateErrorURL()
            End If

        End Sub
        Private Sub cblSCDFields_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cblSCDFields.SelectedIndexChanged
            Dim arrSelectedFields As New ArrayList
            Dim strSelectedSystemFields As String = ""
            Dim strSelectedUDFields As String = ""
            For Each objItem As UI.WebControls.ListItem In cblSCDFields.Items
                If objItem.Selected AndAlso objItem.Value <> "-1" Then
                    arrSelectedFields.Add(objItem.Value.ToString)
                    If objItem.Value.ToString.StartsWith("UD_") Then
                        strSelectedUDFields = strSelectedUDFields + "," + objItem.Value.ToString
                    Else
                        strSelectedSystemFields = strSelectedSystemFields + "," + objItem.Value.ToString
                    End If
                End If
            Next
            Dim EBOFilterOBJ As New MZKForm.MZKErrorBuilder
            If arrSelectedFields.Count > 10 Then
                EBOFilterOBJ.AddError("You can not update more than ten fields at a time.", cblSCDFields)
                Me.ShowErrors(InfoPanel1, EBOFilterOBJ)
            Else
                EBOFilterOBJ.ClearErrorMessage()
                ShowInfoPanel(EBOFilterOBJ.GetErrorMessage, False, False)
                SelectedFields = arrSelectedFields
                If Not strSelectedSystemFields = "" Then
                    SelectedSystemFieldsString = strSelectedSystemFields.Remove(0, 1)
                End If
                If Not strSelectedUDFields = "" Then
                    SelectedUDFieldsString = strSelectedUDFields.Remove(0, 1)
                End If
            End If
            SaveData()
            gvSchedule.Rebind()
        End Sub
    #End Region
    #Region "Methods"
        Public Sub RefreshGrid()
            gvSchedule.Rebind()
        End Sub
        Public Sub InitializeSaveData()
            ViewState("SavedHash") = Nothing
            ViewState("RemoveSavedHash") = Nothing
            hdnCheckAll.Value = "-1"
            hdnCheckedAll.Value = "0"
        End Sub
        Private Sub RegisterScripts()
            Dim l_strStartupScript As Text.StringBuilder = New Text.StringBuilder
            l_strStartupScript.Append("<script language=""javascript"">")
            l_strStartupScript.Append("ApplyOnClickEventTOCheckboxes('")
            l_strStartupScript.Append(cblSCDFields.ClientID)
            l_strStartupScript.Append("');")
            l_strStartupScript.Append("CheckAll('")
            l_strStartupScript.Append(cblSCDFields.ClientID)
            l_strStartupScript.Append("');")
            l_strStartupScript.Append("ApplyOnClickEventTOCheckboxes('")
            l_strStartupScript.Append(cblSCDFields.ClientID)
            l_strStartupScript.Append("');")
            l_strStartupScript.Append("CheckAll('")
            l_strStartupScript.Append(cblSCDFields.ClientID)
            l_strStartupScript.Append("');")
            l_strStartupScript.Append("</script>")
            ScriptManager.RegisterStartupScript(Page, Page.GetType, "onClick", l_strStartupScript.ToString, False)
        End Sub
        Private Sub BindEditableFieldsCheckList()
            Dim drow() As DataRow = DataGridColumns.Select("IsReadOnly=0")
            For i As Integer = 0 To drow.Length - 1
                cblSCDFields.Items.Add(New ListItem(drow(i)("DisplayName"), drow(i)("ColumnName")))
            Next

            Me.cblSCDFields.Items.Insert(0, New ListItem("ALL", "-1"))


            Me.cblSCDFields.Attributes.Add("onclick", "CheckAll('" & Me.cblSCDFields.ClientID & "',0," & Me.cblSCDFields.Items.Count & ")")
            If SelectAllCal Then
                cblSCDFields.Items.FindByText("ALL").Selected = True
                Dim l_strStartupScript As Text.StringBuilder = New Text.StringBuilder
                l_strStartupScript.Append("<script language=""javascript"">")
                l_strStartupScript.Append("CheckAll('" & cblSCDFields.ClientID & "',0," & cblSCDFields.Items.Count & ")")
                l_strStartupScript.Append("</script>")
                ScriptManager.RegisterStartupScript(Page, Page.GetType, "CheckAll", l_strStartupScript.ToString, False)
            End If
        End Sub
        Private Sub CreateDataGridColumns()
            Dim cols As DataTable
            cols = DataGridColumns
            gvSchedule.MasterTableView.AutoGenerateColumns = False
            gvSchedule.MasterTableView.TableLayout = GridTableLayout.Fixed
            gvSchedule.MasterTableView.HeaderStyle.Wrap = True
            gvSchedule.MasterTableView.HeaderStyle.HorizontalAlign = HorizontalAlign.Center
            gvSchedule.MasterTableView.HeaderStyle.VerticalAlign = VerticalAlign.Middle
            gvSchedule.MasterTableView.ItemStyle.Wrap = True
            gvSchedule.MasterTableView.ItemStyle.HorizontalAlign = HorizontalAlign.Center
            gvSchedule.MasterTableView.ItemStyle.VerticalAlign = VerticalAlign.Middle
            gvSchedule.MasterTableView.DataKeyNames = New String() {"SCD_ID"}
            'gvSchedule.MasterTableView.Width = Unit.Pixel(1024)
            If Not cols Is Nothing Then
                For Each row As DataRow In cols.Rows
                    Dim colName As String = row.Item("ColumnName")
                    Dim viewColName As String = row.Item("DisplayName")
                    Dim isReadOnly As Boolean = row.Item("IsReadOnly")
                    Dim ddlType As String = String.Empty
                    Dim dataDefType As Integer = -1
                    Dim storedProcedure As String = String.Empty
                    If Not row.Item("ddlType") Is Nothing AndAlso Not IsDBNull(row.Item("ddlType")) Then
                        ddlType = row.Item("ddlType")
                    End If
                    If Not row.Item("DataDefType") Is Nothing AndAlso Not IsDBNull(row.Item("DataDefType")) AndAlso IsNumeric(row.Item("DataDefType")) Then
                        dataDefType = CInt(row.Item("DataDefType"))
                    End If
                    If Not row.Item("StoredProcedure") Is Nothing AndAlso Not IsDBNull(row.Item("StoredProcedure")) Then
                        storedProcedure = row.Item("StoredProcedure")
                    End If
                    Dim ContentType As Integer = row("ContentType").ToString
                    Dim templateColumn As Telerik.Web.UI.GridTemplateColumn = New Telerik.Web.UI.GridTemplateColumn()
                    gvSchedule.Columns.Add(templateColumn)
                    templateColumn.ItemTemplate = New SCDGridColumnTemplate(ListItemType.Item, colName, viewColName, isReadOnly, ContentType, row.Item("ShowMassUpdate"), row.Item("CssClass"), ddlType, dataDefType, storedProcedure)
                    'templateColumn.HeaderText = viewColName
                    templateColumn.HeaderTemplate = New SCDGridColumnTemplate(ListItemType.Header, colName, viewColName, isReadOnly, ContentType, row.Item("ShowMassUpdate"), row.Item("CssClass"), ddlType, dataDefType, storedProcedure)
                    If ContentType = 6 Then
                        templateColumn.Display = False
                    End If
                    templateColumn.ItemStyle.Width = Unit.Pixel(150)
                    templateColumn.HeaderStyle.Width = Unit.Pixel(150)
                    templateColumn.AllowFiltering = False
                    templateColumn.SortExpression = colName
                    templateColumn.AllowSorting = True
                    templateColumn.HeaderStyle.VerticalAlign = VerticalAlign.Middle
                    templateColumn.ItemStyle.VerticalAlign = VerticalAlign.Middle
                    templateColumn.HeaderStyle.HorizontalAlign = HorizontalAlign.Center
                    templateColumn.ItemStyle.HorizontalAlign = HorizontalAlign.Center
                Next
            End If
        End Sub
        Private Sub RetrieveDataFromMiddleTier(ByRef pFO As FetchingOptions)
            Dim l_SchoolDomain = -1
            Dim l_strFrom As String = Session.Item("SC_from")
            If l_strFrom = "_DADMIN" Then
                l_SchoolDomain = -1
            Else
                If l_strFrom = "_SADMIN" Then
                    l_SchoolDomain = TEMSSecurity.CurrentSchool
                End If
            End If
            Dim ds As New DataSet
            Dim cc As New MZKObj.MZKObj.School.SCDetails(TEMSSecurity.UserDistrict)
            ds = cc.RetrieveDataSetForMassSCDates(l_SchoolDomain, TEMSSecurity.CurrentAyIdentifier, pFO)
            DataGridContent = ds.Tables(0).Copy()
            RecordCount = pFO.RecordCount
        End Sub
        Private Sub RetrieveSCDFields()
            Dim ds As New DataSet
            Dim cc As New MZKObj.MZKObj.School.SCDetails(TEMSSecurity.UserDistrict)
            ds = cc.RetrieveDataSetForSCDFields()
            DataGridColumns = ds.Tables(0).Copy()
        End Sub
    #End Region

    #Region "RadGrid Events"
        Private Sub gvSchedule_NeedDataSource(sender As Object, e As GridNeedDataSourceEventArgs) Handles gvSchedule.NeedDataSource
            BindGrid()
        End Sub
        Private Sub BindGrid()
            Dim sort As String = gvSchedule.MasterTableView.SortExpressions.GetSortString()
            If sort Is Nothing Then
                sort = "SCName"
            End If
            Filter = GetFilterString()
            Dim fo As New FetchingOptions
            FilterFactory(fo)
            fo.Filter = Filter
            If Not PageIndex = Nothing Then
                fo.PageNumber = PageIndex
            Else
                fo.PageCount = gvSchedule.CurrentPageIndex
            End If

            fo.NumberOfRecords = gvSchedule.PageSize
            fo.SortExpression = sort
            RetrieveDataFromMiddleTier(fo)
            gvSchedule.VirtualItemCount = RecordCount
            gvSchedule.DataSource = DataGridContent
        End Sub
        Protected Sub gvSchedule_ItemDataBound(sender As Object, e As Telerik.Web.UI.GridItemEventArgs) Handles gvSchedule.ItemDataBound
            If TypeOf e.Item Is GridDataItem Then

                Dim dr() As DataRow
                'set the checkbox state
                If Not e.Item.FindControl("chkItem") Is Nothing Then
                    Dim checkedItems As HybridDictionary = New HybridDictionary
                    Dim uncheckedItems As HybridDictionary = New HybridDictionary
                    If Not ViewState("SavedHash") Is Nothing Then
                        checkedItems = CType(ViewState("SavedHash"), HybridDictionary)
                    End If
                    If Not ViewState("RemoveSavedHash") Is Nothing Then
                        uncheckedItems = CType(ViewState("RemoveSavedHash"), HybridDictionary)
                    End If
                    Dim cb As HtmlInputCheckBox = CType(e.Item.FindControl("chkItem"), HtmlInputCheckBox)

                    Dim intSCD_ID As Integer = -1
                    If e.Item.FindControl("dynCellControl!SCD_ID") IsNot Nothing Then
                        intSCD_ID = CType(e.Item.FindControl("dynCellControl!SCD_ID"), HiddenField).Value
                    Else
                        intSCD_ID = cb.Value
                    End If
                    dr = DataGridContent.Select("SCD_ID=" & intSCD_ID) 'get the row in the dataset that corresponds with the row currently being bound in the grid
                    If hdnCheckAll.Value = "1" OrElse checkedItems.Contains(cb.Value) OrElse (hdnCheckedAll.Value = 1 AndAlso Not (uncheckedItems.Contains(cb.Value))) Then
                        cb.Checked = True
                        If checkedItems.Contains(cb.Value) Then
                            UpdateDataRow(dr, checkedItems, cb.Value)
                        End If
                    Else
                        cb.Checked = False
                    End If
                End If


                Dim item As GridDataItem = DirectCast(e.Item, GridDataItem)
                Dim dtDataGridColumns As DataTable = DataGridColumns
                For Each bColumn As DataRow In dtDataGridColumns.Rows
                    Dim ContentType As Integer = bColumn("ContentType").ToString
                    Dim ColumnName As String = bColumn("ColumnName").ToString

                    Dim data As String = String.Empty
                    Dim massUpdateItem As HybridDictionary = LoadDictionaryforMassUpdateControl(hdnMassUpdateControlsSelected.Value)
                    If massUpdateItem.Contains(ColumnName) AndAlso hdnCheckAll.Value = "1" Then
                        data = massUpdateItem.Item(ColumnName).ToString()
                    ElseIf dr.Length > 0 AndAlso dr(0).Table.Columns.Contains(ColumnName) Then
                        If Not dr(0)(ColumnName) Is Nothing AndAlso Not IsDBNull(dr(0)(ColumnName)) Then
                            data = dr(0)(ColumnName) 'get the data from the dataset, if present
                        Else
                            data = ""
                        End If
                    Else
                        data = ""
                    End If

                    Dim blnIsEdit As Boolean = False
                    If SelectedFields IsNot Nothing Then
                        For i As Integer = 0 To SelectedFields.Count - 1
                            If SelectedFields.Item(i).ToString() = ColumnName _
                                AndAlso cblSCDFields.Items.FindByText(bColumn("DisplayName").ToString) IsNot Nothing _
                                AndAlso cblSCDFields.Items.FindByText(bColumn("DisplayName").ToString).Selected Then
                                blnIsEdit = True
                            End If
                        Next
                    End If
                    If blnIsEdit Then
                        Select Case ContentType
                            Case 1
                                Dim txt As New TextBox()
                                txt = DirectCast(item.FindControl("dynCellControl!" + ColumnName), TextBox)
                                txt.Enabled = True
                                If Not data = String.Empty Or Not data = "" Then
                                    txt.Text = data
                                End If

                                Exit Select
                            Case 4
                                Dim txt As New RadDatePicker()
                                txt = DirectCast(item.FindControl("dynCellControl!" + ColumnName), RadDatePicker)
                                txt.Enabled = True
                                If Not data = String.Empty Or Not data = "" Then
                                    txt.DbSelectedDate = data
                                End If
                                Exit Select
                            Case 2
                                Dim ddl As New DropDownList()
                                ddl = DirectCast(item.FindControl("dynCellControl!" + ColumnName), DropDownList)
                                ddl.Enabled = True
                                If Not data = String.Empty Or Not data = "" Then
                                    If ddl.Items.FindByValue(data.Trim()) IsNot Nothing Then
                                        ddl.SelectedValue = data.Trim()
                                    End If

                                End If
                                Exit Select
                            Case 3
                                Dim ddl As New DropDownList()
                                ddl = DirectCast(item.FindControl("dynCellControl!" + ColumnName), DropDownList)
                                ddl.Enabled = True
                                If Not data = String.Empty Or Not data = "" Then
                                    ddl.SelectedValue = data
                                End If
                                Exit Select
                            Case 5
                                Dim chk As New CheckBox()
                                chk = DirectCast(item.FindControl("dynCellControl!" + ColumnName), CheckBox)
                                chk.Enabled = True
                                If Not data = String.Empty Or Not data = "" Then
                                    If data.ToLower = "true" Then
                                        chk.Checked = True
                                    Else
                                        chk.Checked = False
                                    End If
                                End If
                                Exit Select
                            Case 7, 8
                                Dim lbl As New Label()
                                lbl = DirectCast(item.FindControl("dynCellControl!" + ColumnName), Label)
                                lbl.Enabled = True
                                Exit Select

                            Case 10
                                Dim htmlchk As New HtmlControls.HtmlInputCheckBox()
                                htmlchk = DirectCast(item.FindControl("dynCellControl!" + ColumnName), HtmlInputCheckBox)
                                htmlchk.Disabled = False
                                If Not data = String.Empty Or Not data = "" Then
                                    If data.ToLower = "true" Then
                                        htmlchk.Checked = True
                                    Else
                                        htmlchk.Checked = False
                                    End If
                                End If
                                Exit Select
                        End Select
                    End If
                Next

            End If
            If TypeOf e.Item Is GridHeaderItem Then
                If e.Item.NamingContainer.Controls.Count > 0 AndAlso e.Item.NamingContainer.Controls(0).FindControl("ClearFilter") IsNot Nothing Then
                    e.Item.NamingContainer.Controls(0).FindControl("ClearFilter").Visible = False
                End If
                Dim massUpdateItem As HybridDictionary = LoadDictionaryforMassUpdateControl(hdnMassUpdateControlsSelected.Value)

                Dim item As GridHeaderItem = DirectCast(e.Item, GridHeaderItem)
                Dim dtDataGridColumns As DataTable = DataGridColumns
                For Each bColumn As DataRow In dtDataGridColumns.Rows
                    Dim ContentType As Integer = bColumn("ContentType").ToString
                    Dim ColumnName As String = bColumn("ColumnName").ToString
                    Dim data As String = String.Empty
                    If hdnCheckAll.Value = "1" Then
                        If e.Item.FindControl("checkAll") IsNot Nothing Then
                            CType(e.Item.FindControl("checkAll"), HtmlInputCheckBox).Checked = True
                        End If
                        If massUpdateItem.Contains(ColumnName) Then
                            data = massUpdateItem.Item(ColumnName).ToString()
                        End If
                    End If
                    Dim blnIsEdit As Boolean = False
                    If SelectedFields IsNot Nothing Then
                        For i As Integer = 0 To SelectedFields.Count - 1
                            If SelectedFields.Item(i).ToString() = ColumnName _
                                AndAlso cblSCDFields.Items.FindByText(bColumn("DisplayName").ToString) IsNot Nothing _
                                AndAlso cblSCDFields.Items.FindByText(bColumn("DisplayName").ToString).Selected Then
                                blnIsEdit = True
                            End If
                        Next
                    End If
                    If blnIsEdit Then
                        Select Case ContentType
                            Case ContentTypes.textBox
                                Dim txt As New TextBox()
                                txt = DirectCast(item.FindControl("dynMassUpdateControl!" + ColumnName), TextBox)
                                txt.Enabled = True
                                txt.Visible = True
                                If Not data = String.Empty Or Not data = "" Then
                                    txt.Text = data
                                End If
                                Exit Select
                            Case ContentTypes.date
                                Dim txt As New RadDatePicker()
                                txt = DirectCast(item.FindControl("dynMassUpdateControl!" + ColumnName), RadDatePicker)
                                txt.Enabled = True
                                txt.Visible = True
                                If Not data = String.Empty Or Not data = "" Then
                                    txt.DbSelectedDate = data
                                End If
                                Exit Select
                            Case ContentTypes.dropDownList
                                Dim ddl As New DropDownList()
                                ddl = DirectCast(item.FindControl("dynMassUpdateControl!" + ColumnName), DropDownList)
                                ddl.Enabled = True
                                ddl.Visible = True
                                If Not data = String.Empty Or Not data = "" Then
                                    If ddl.Items.FindByValue(data.Trim()) IsNot Nothing Then
                                        ddl.SelectedValue = data.Trim()
                                    End If
                                End If
                                Exit Select
                            Case ContentTypes.dataDefinition
                                Dim ddl As New DropDownList()
                                ddl = DirectCast(item.FindControl("dynMassUpdateControl!" + ColumnName), DropDownList)
                                ddl.Enabled = True
                                ddl.Visible = True
                                If Not data = String.Empty Or Not data = "" Then
                                    ddl.SelectedValue = data
                                End If
                                Exit Select
                            Case ContentTypes.checkBox
                                Dim chk As New HtmlInputCheckBox()
                                chk = DirectCast(item.FindControl("dynMassUpdateControl!" + ColumnName), HtmlInputCheckBox)
                                chk.Disabled = False
                                chk.Visible = True
                                If Not data = String.Empty Or Not data = "" Then
                                    If data.ToLower = "true" Then
                                        chk.Checked = True
                                    Else
                                        chk.Checked = False
                                    End If
                                End If
                                Exit Select
                            Case ContentTypes.label, ContentTypes.changeableLabel
                                Dim lbl As New Label()
                                lbl = DirectCast(item.FindControl("dynMassUpdateControl!" + ColumnName), Label)
                                lbl.Enabled = True
                                lbl.Visible = True
                                Exit Select

                            Case ContentTypes.htmlcheckbox
                                Dim htmlchk As New HtmlControls.HtmlInputCheckBox()
                                htmlchk = DirectCast(item.FindControl("dynMassUpdateControl!" + ColumnName), HtmlInputCheckBox)
                                htmlchk.Disabled = False
                                htmlchk.Visible = True
                                If Not data = String.Empty Or Not data = "" Then
                                    If data.ToLower = "true" Then
                                        htmlchk.Checked = True
                                    Else
                                        htmlchk.Checked = False
                                    End If
                                End If
                                Exit Select
                        End Select
                    End If
                Next
            End If
        End Sub
        Private Sub gvSchedule_PreRender(sender As Object, e As EventArgs) Handles gvSchedule.PreRender

            Dim header As GridItem() = gvSchedule.MasterTableView.GetItems(GridItemType.Header)
            Dim head As GridTHead = DirectCast(header(0).Parent.Controls(0).Parent, GridTHead)
            Dim currentHeaderItem As GridHeaderItem
            Dim currentPagerItem As GridPagerItem ''() = gvSchedule.MasterTableView.GetItems(GridItemType.Pager)
            Dim currentExportItem As GridCommandItem
            For i As Integer = 0 To head.Controls.Count - 1
                If TypeOf head.Controls(i) Is GridHeaderItem Then
                    currentHeaderItem = DirectCast(head.Controls(i), GridHeaderItem)
                End If
                If TypeOf head.Controls(i) Is GridPagerItem Then
                    currentPagerItem = DirectCast(head.Controls(i), GridPagerItem)
                End If
                If TypeOf head.Controls(i) Is GridCommandItem Then
                    currentExportItem = DirectCast(head.Controls(i), GridCommandItem)
                End If
                If TypeOf head.Controls(i) Is GridFilteringItem Then
                    head.Controls.Remove(head.Controls(i))
                End If
            Next

            'Clear all GridHeaderItems   
            ' head.Controls.Clear()
            'create a new GridHeaderItem which will be the new row   
            Dim hdr1Item As New GridHeaderItem(gvSchedule.MasterTableView, 0, 0)
            Dim hdr2Item As New GridHeaderItem(gvSchedule.MasterTableView, 0, 0)

            Dim cloneDT As DataTable = DataGridColumns
            cloneDT.Columns.Add("IsUsed", GetType(Boolean))
            For Each row As DataRow In cloneDT.Rows
                row("IsUsed") = False
            Next

            For i As Integer = 0 To 2
                Dim cell = New GridTableHeaderCell()
                Dim lbl As LinkButton = New LinkButton()
                lbl.Text = ""
                lbl.CssClass = "bodytext"
                cell.Controls.Add(lbl)
                hdr1Item.Cells.Add(cell)
            Next

            For Each headercell As GridTableHeaderCell In currentHeaderItem.Cells
                Dim str As String = ""
                For Each dr As DataRow In cloneDT.Rows
                    If Not headercell.FindControl("dynMassUpdateControl!" + dr("ColumnName").ToString) Is Nothing AndAlso dr("IsUsed") = False Then
                        str = dr("DisplayName").ToString
                        dr("IsUsed") = True
                        Dim cell = New GridTableHeaderCell()
                        Dim lbl As LinkButton = New LinkButton()
                        lbl.Text = str
                        lbl.ForeColor = Drawing.Color.White
                        lbl.CommandName = "Sort"
                        lbl.CommandArgument = dr("ColumnName").ToString
                        lbl.ToolTip = "Sort"
                        cell.Controls.Add(lbl)
                        hdr1Item.Cells.Add(cell)
                        Exit For
                    End If
                Next
            Next
            'hdr1Item.Width = Unit.Pixel(200)
            'If Not currentExportItem Is Nothing Then
            '    head.Controls.Add(currentExportItem)
            'End If
            'If Not currentPagerItem Is Nothing Then
            '    head.Controls.Add(currentPagerItem)
            'End If
            head.Controls.Add(hdr1Item)
            head.Controls.Add(currentHeaderItem)

        End Sub

        Private Sub gvSchedule_GridDataExport(e As MZKGrids.ExportTypeEventArgs) Handles gvSchedule.GridDataExport
            PrepareGirdForExport()
            If e.ExportType = "ExportExcel" Then
                gvSchedule.MasterTableView.ExportToExcel()
            End If
            If e.ExportType = "ExportCSV" Then
                gvSchedule.SetCSVOptionsForExport()
                gvSchedule.MasterTableView.ExportToCSV()
            End If
            If e.ExportType = "ExportPDF" Then
                gvSchedule.SetPDFOptionsForExport()
                gvSchedule.MasterTableView.ExportToPdf()
            End If
        End Sub
        Private Sub PrepareGirdForExport()
            gvSchedule.MasterTableView.GetColumn("Select").Visible = False
            gvSchedule.ExportSettings.FileName = Guid.NewGuid().ToString()
            gvSchedule.PageSize = gvSchedule.VirtualItemCount
            gvSchedule.CurrentPageIndex = 0
            gvSchedule.Rebind()
        End Sub
    #End Region



    #Region "Preserve Functions"
        Protected ReadOnly Property GetSelectedMassUpdateControls() As ListDictionary
            Get
                Dim ld As New ListDictionary
                Dim id As String = String.Empty
                Dim val As String = String.Empty
                Dim sep(0) As String
                sep(0) = ",MUC,"

                For Each item As String In hdnMassUpdateControlsSelected.Value.ToString.Trim.Split(sep, StringSplitOptions.RemoveEmptyEntries)
                    id = item.Substring(0, item.IndexOf("=MUC=")).ToString.Trim
                    val = item.Substring(item.IndexOf("=MUC=") + 5).ToString.Trim
                    If ld.Contains(id) Then
                        ld.Remove(id)
                    End If
                    ld.Add(id, val)
                Next
                Return ld
            End Get
        End Property
        Private Sub SaveData()
            Dim checkedItems As HybridDictionary = New HybridDictionary
            Dim uncheckedItems As HybridDictionary = New HybridDictionary
            'Dim massUpdateItems As HybridDictionary = New HybridDictionary

            If hdnCheckAll.Value = "0" Then
                ViewState("SavedHash") = Nothing
                ViewState("RemoveSavedHash") = Nothing
                hdnCheckAll.Value = "-1"
            End If

            If Not ViewState("SavedHash") Is Nothing Then
                checkedItems = CType(ViewState("SavedHash"), HybridDictionary)
            End If

            If Not ViewState("RemoveSavedHash") Is Nothing Then
                uncheckedItems = CType(ViewState("RemoveSavedHash"), HybridDictionary)
            End If

            If gvSchedule.Columns.Count <= 3 Then
                gvSchedule.Rebind()
            End If

            For Each dgi As GridDataItem In gvSchedule.Items
                Dim cb As HtmlInputCheckBox = dgi.FindControl("chkItem")
                If Not cb Is Nothing Then
                    If hdnCheckAll.Value = "1" OrElse cb.Checked Then
                        If checkedItems.Contains(CStr(cb.Value)) Then
                            checkedItems.Remove(cb.Value)
                        End If
                        checkedItems.Add(CStr(cb.Value), CreateDataTableFromDataGridItem(dgi))
                        If uncheckedItems.Contains(CStr(cb.Value)) Then
                            uncheckedItems.Remove(cb.Value)
                        End If
                    Else
                        If checkedItems.Contains(CStr(cb.Value)) Then
                            checkedItems.Remove(CStr(cb.Value))
                        End If
                        If Not uncheckedItems.Contains(CStr(cb.Value)) Then
                            'uncheckedItems.Add(CStr(cb.Value), CStr(cb.Value))
                            uncheckedItems.Add(CStr(cb.Value), CStr(cb.Value))
                        End If
                    End If
                End If
            Next
            ' massUpdateItems = LoadDictionaryforMassUpdateControl(hdnMassUpdateControlsSelected.Value)

            'Me.ViewState.Add("SaveMassUpdateControl", massUpdateItems)
            Me.ViewState.Add("SavedHash", checkedItems)
            ViewState("RemoveSavedHash") = uncheckedItems
        End Sub
        Private Function CreateDataTableFromDataGridItem(ByVal dgi As GridDataItem) As DataTable
            Dim dt As DataTable = getDataTableStructure()
            Dim dr As DataRow
            dr = dt.NewRow
            Dim data As String = String.Empty
            Dim temCol As SCDGridColumnTemplate ''= New SCDGridColumnTemplate
            Dim tc As TableCell
            Dim i As Integer = 0
            While i < dgi.Cells.Count
                'For Each dataRow As DataRow In dt.Rows
                For Each dataColumn As DataColumn In dt.Columns
                    Dim columnName As String = dataColumn.ColumnName
                    Dim ContentType As String = DataGridColumns.Select("ColumnName='" + dataColumn.ColumnName + "'")(0)("ContentType").ToString
                    Dim DataTypeType As String = DataGridColumns.Select("ColumnName='" + dataColumn.ColumnName + "'")(0)("OriginalContentType").ToString
                    Select Case ContentType

                        Case ContentTypes.textBox
                            Dim ctrl As TextBox
                            If Not dgi.FindControl("dynCellControl!" + columnName) Is Nothing AndAlso Not CType(dgi.FindControl("dynCellControl!" + columnName), TextBox).Text = "" Then
                                ctrl = CType(dgi.FindControl("dynCellControl!" + columnName), TextBox)
                                dr(columnName) = ctrl.Text
                                'Return ctrl.Text
                            Else
                                'If DataTypeType = 1 Then
                                '    dr(columnName) = "0"
                                'ElseIf DataTypeType = 2 Then
                                '    dr(columnName) = "0.00"
                                'ElseIf DataTypeType = 3 Then
                                '    dr(columnName) = String.Empty
                                'End If
                                dr(columnName) = String.Empty
                            End If

                        Case ContentTypes.label, ContentTypes.changeableLabel
                            Dim ctrl As Label
                            If Not dgi.FindControl("dynCellControl!" + columnName) Is Nothing Then
                                ctrl = CType(dgi.FindControl("dynCellControl!" + columnName), Label)
                                dr(columnName) = ctrl.Text
                            Else
                                dr(columnName) = String.Empty
                            End If

                        Case ContentTypes.hidden
                            Dim ctrl As HiddenField
                            If Not dgi.FindControl("dynCellControl!" + columnName) Is Nothing Then
                                ctrl = CType(dgi.FindControl("dynCellControl!" + columnName), HiddenField)
                                dr(columnName) = ctrl.Value
                            Else
                                dr(columnName) = String.Empty
                            End If

                        Case ContentTypes.dropDownList
                            Dim ctrl As DropDownList
                            If Not dgi.FindControl("dynCellControl!" + columnName) Is Nothing Then
                                ctrl = CType(dgi.FindControl("dynCellControl!" + columnName), DropDownList)
                                If ctrl.Items.Count > 0 Then
                                    If ctrl.SelectedValue = _ddlSelectItem Then
                                        dr(columnName) = String.Empty
                                    Else
                                        dr(columnName) = ctrl.SelectedValue
                                    End If
                                Else
                                    dr(columnName) = String.Empty
                                End If
                            Else
                                dr(columnName) = String.Empty
                            End If

                        Case ContentTypes.checkBox
                            Dim ctrl As CheckBox
                            If Not dgi.FindControl("dynCellControl!" + columnName) Is Nothing Then
                                ctrl = CType(dgi.FindControl("dynCellControl!" + columnName), CheckBox)
                                If ctrl.Checked Then
                                    dr(columnName) = "True"
                                Else
                                    dr(columnName) = "False"
                                End If
                            Else
                                dr(columnName) = "False"
                            End If

                        Case ContentTypes.dataDefinition
                            Dim ctrl As DropDownList
                            If Not dgi.FindControl("dynCellControl!" + columnName) Is Nothing Then
                                ctrl = CType(dgi.FindControl("dynCellControl!" + columnName), DropDownList)
                                If ctrl.Items.Count > 0 Then
                                    If ctrl.SelectedValue = _ddlSelectItem Then
                                        dr(columnName) = String.Empty
                                    Else
                                        dr(columnName) = ctrl.SelectedValue
                                    End If
                                Else
                                    dr(columnName) = String.Empty
                                End If
                            Else
                                dr(columnName) = String.Empty
                            End If

                        Case ContentTypes.date
                            Dim ctrl As TextBox
                            If Not dgi.FindControl("dynCellControl!" + columnName) Is Nothing AndAlso Not CType(dgi.FindControl("dynCellControl!" + columnName), TextBox).Text = "" Then
                                ctrl = CType(dgi.FindControl("dynCellControl!" + columnName), TextBox)
                                dr(columnName) = ctrl.Text
                            Else
                                dr(columnName) = String.Empty
                            End If

                        Case Else
                            dr(columnName) = String.Empty
                    End Select
                Next
                i = i + 1
            End While

            dt.Rows.Add(dr)
            dt.AcceptChanges()
            Return dt
        End Function
        Private Function ContainColumn(columnName As String, table As DataTable) As Boolean
            Dim columns As DataColumnCollection = table.Columns
            If columns.Contains(columnName) Then
                Return True
            Else
                Return False
            End If
        End Function
        Private Function getDataTableStructure() As DataTable ''' Add Columns In DataTable
            Dim cols As DataTable = DataGridColumns
            Dim dt As DataTable = New DataTable
            If Not cols Is Nothing Then
                For Each row As DataRow In cols.Rows

                    If SaveColumnData(row.Item("ColumnName")) Then
                        dt.Columns.Add(New DataColumn(row.Item("ColumnName")))
                    End If

                Next
            End If
            Return dt
        End Function
        Private Function SaveColumnData(ByVal pstrColumnName As String) As Boolean
            If Not SelectedFields Is Nothing AndAlso SelectedFields.Contains(pstrColumnName) OrElse pstrColumnName.Trim = "SCD_ID" Then
                Return True
            End If
            Return False
        End Function
        Private Function LoadDictionaryforMassUpdateControl(hdnValue As String) As HybridDictionary
            Dim l_oDictionary As HybridDictionary = New HybridDictionary
            Dim l_aList As Array = hdnValue.Split(New String() {",MUC,"}, StringSplitOptions.RemoveEmptyEntries)
            Dim l_aControl As Array

            For Each row As String In l_aList
                l_aControl = row.Split(New String() {"=MUC="}, StringSplitOptions.RemoveEmptyEntries)
                l_oDictionary.Add(l_aControl(0), l_aControl(1))
            Next
            Return l_oDictionary
        End Function
        Private Function UpdateDataRow(ByRef dr() As DataRow, ByRef item As HybridDictionary, ByVal val As String)
            Dim tempRow As DataRow
            tempRow = CType(item.Item(val), DataTable).Rows(0)
            If Not tempRow Is Nothing Then
                If tempRow.Table.Rows.Count > 0 AndAlso tempRow.Table.Columns.Count > 1 Then
                    dr = tempRow.Table.Select()
                End If
            End If
        End Function
    #End Region

    #Region "Mass Update functions"
        Private Function Validate(ByRef poEbObj As MZKObj.MZKObj.MZKForm.MZKErrorBuilder, ByVal ds As DataSet) As Boolean
            poEbObj.ClearErrorMessage()

            If ds Is Nothing OrElse ds.Tables.Count < 1 OrElse ds.Tables(0).Rows.Count < 1 Then
                poEbObj.AddError("Please select at least one record in the grid")
            End If

            If poEbObj.GetErrorsCount > 0 Then
                Return False
            Else
                Return True
            End If
        End Function
        Public Sub Update(Optional ByRef poEbObj As MZKObj.MZKObj.MZKForm.MZKErrorBuilder = Nothing)
            If poEbObj Is Nothing Then
                poEbObj = New MZKObj.MZKObj.MZKForm.MZKErrorBuilder()
            End If
            SaveData()
            Dim ds As DataSet = GetRowsToProcess()
            If Validate(poEbObj, ds) Then
                Dim l_strSystemFields As String = ""
                If Not SelectedSystemFieldsString Is Nothing Then
                    l_strSystemFields = SelectedSystemFieldsString
                End If
                Dim l_strUDFields As String = ""
                If Not SelectedUDFieldsString Is Nothing Then
                    l_strUDFields = SelectedUDFieldsString
                End If
                Dim scd As New MZKObj.MZKObj.School.SCDetails(TEMSSecurity.UserDistrict)

                Dim oRetVal As Boolean = scd.MassUpdateSCDates(ds, TEMSSecurity.MemId, l_strSystemFields, l_strUDFields)
                hdnMassUpdateControlsSelected.Value = ""
                hdnCheckAll.Value = "-1"
                hdnCheckedAll.Value = "0"
                ViewState("SavedHash") = Nothing
                ViewState("RemoveSavedHash") = Nothing

            End If
            gvSchedule.Rebind()
        End Sub
        Private Function GetRowsToProcess() As DataSet
            Dim checkedItems As HybridDictionary = New HybridDictionary
            If Not ViewState("SavedHash") Is Nothing Then
                checkedItems = CType(ViewState("SavedHash"), HybridDictionary)
            End If
            Dim uncheckedItems As HybridDictionary = New HybridDictionary
            If Not ViewState("RemoveSavedHash") Is Nothing Then
                uncheckedItems = CType(ViewState("RemoveSavedHash"), HybridDictionary)
            End If

            Dim dt As DataTable = getDataTableStructure()
            Dim dr() As DataRow
            Dim SCD_ID As String = String.Empty

            If hdnCheckAll.Value = "1" OrElse hdnCheckedAll.Value = "1" Then
                Dim fo As New FetchingOptions
                FilterFactory(fo)
                fo.Filter = Filter()
                fo.SortExpression = "SCName"
                fo.NumberOfRecords = 0
                RetrieveDataFromMiddleTier(fo)
                If Not DataGridContent Is Nothing Then
                    For Each row As DataRow In DataGridContent.Rows
                        If Not row.Item("SCD_ID") Is Nothing AndAlso Not IsDBNull(row.Item("SCD_ID")) AndAlso IsNumeric(row.Item("SCD_ID")) Then
                            SCD_ID = row.Item("SCD_ID")

                            If checkedItems.Contains(SCD_ID) Then
                                row = CType(checkedItems(SCD_ID), DataTable).Rows(0)
                                ProcessRowForMassUpdateControls(row)
                                dt.ImportRow(row)
                            ElseIf Not hdnCheckAll.Value = "1" Then
                                If Not uncheckedItems.Contains(SCD_ID) Then
                                    ProcessRowForMassUpdateControls(row)
                                    dt.ImportRow(row)
                                End If
                            Else
                                ProcessRowForMassUpdateControls(row)
                                dt.ImportRow(row)
                            End If
                        End If
                    Next

                End If
            Else
                If Not checkedItems Is Nothing Then
                    For Each di As DictionaryEntry In checkedItems
                        If Not di.Value Is Nothing Then
                            dt.ImportRow(CType(di.Value, DataTable).Rows(0))
                        End If
                    Next

                End If
            End If

            dt.AcceptChanges()
            Dim ds As New DataSet
            ds.Tables.Add(dt)
            ds.AcceptChanges()
            Return ds
        End Function
        Private Sub ProcessRowForMassUpdateControls(ByRef row As DataRow)
            For Each dataItem As DataRow In DataGridColumns.Rows  ''gvSchedule.MasterTableView.Items
                If GetSelectedMassUpdateControls.Contains(dataItem("ColumnName").ToString) Then
                    If SaveColumnData(dataItem("ColumnName").ToString) Then
                        row.Item(dataItem("ColumnName").ToString) = GetSelectedMassUpdateControls(dataItem("ColumnName").ToString)
                    End If
                End If
            Next


        End Sub
    #End Region

        Private Sub InitializeDefaultParams()
            InfoPanel1.Visible = False
            'ctrlInfoExt.Visible = False       
        End Sub
        Private Sub ShowInfoPanel(ByVal pstrMessage As String, ByVal pisError As Boolean, ByVal pisVisible As Boolean)
            InfoPanel1.TextInfo = pstrMessage
            InfoPanel1.IsError = pisError
            InfoPanel1.Visible = pisVisible
        End Sub

        Private Sub lnkMassUpdate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkMassUpdate.Click
            Dim l_oError As MZKObj.MZKObj.MZKForm.MZKErrorBuilder = New MZKObj.MZKObj.MZKForm.MZKErrorBuilder()
            Update(l_oError)
            If l_oError.GetErrorsCount > 0 Then
                ShowInfoPanel(l_oError.GetErrorMessage(), True, True)
            Else
                ShowInfoPanel("Selected scheduling calendar dates updated successfully.", False, True)
            End If
        End Sub
        Private Sub FlyoutItems()
            obFlyoutActions.Title = "Actions"
            obFlyoutActions.AddFlyoutItem(New FlyoutItems("Search", lnkSearch.UniqueID, "../../Images/Icons/addnewicon.gif", "Search", TEMS.TEMSSecurity.IsPrivilegeAssigned(Privileges.ViewDistrictHolidays)))
            obFlyoutActions.Visible = True
        End Sub

        Private Sub lnkSearch_Click(sender As Object, e As EventArgs) Handles lnkSearch.Click
            Filter = GetFilterString()
            gvSchedule.DataSource = DataGridContent.DefaultView
            gvSchedule.Rebind()

        End Sub

        Private Sub FillConfigurationGroup()
            datadefAttConfigGroup_ID.DataDefSelectedType = DataDefType.StudentRegCodes
            datadefAttConfigGroup_ID.DataDefCode = DataDefinitions.StudentRegistrationCodes.ConfigurationGroup
            datadefAttConfigGroup_ID.DataValueField = "DF_ID"
        End Sub
        Private Sub FillScheduleCalendarDDL()
            Dim schooldomain As String = TEMSSecurity.CurrentAyIdentifier
            Dim l_strFrom As String = Session.Item("SC_from")
            If l_strFrom = "_DADMIN" Then
                schooldomain = -1
            Else
                If l_strFrom = "_SADMIN" Then
                    schooldomain = TEMSSecurity.CurrentSchool
                End If
            End If
            Dim poFetchingOptions As MZKObj.FetchingOptions = New FetchingOptions()
            Dim l_oDS As DataSet
            poFetchingOptions.SortExpression = "SCName ASC"
            poFetchingOptions.NumberOfRecords = 0
            l_oDS = School.ScheduleCalendar.GetActiveScheduleCalendarModifiedGrid(poFetchingOptions, TEMSSecurity.LoginId, TEMSSecurity.CurrentAyIdentifier, schooldomain, TEMSSecurity.UserDistrict)
            ddlScheduleCalendar.DataSource = l_oDS
            ddlScheduleCalendar.DataTextField = "SCName"
            ddlScheduleCalendar.DataValueField = "SC_ID"
            ddlScheduleCalendar.DataBind()
            ddlScheduleCalendar.Items.Insert(0, New ListItem("All", "-1"))
            If Request.QueryString("SCID") IsNot Nothing Then
                ddlScheduleCalendar.SelectedValue = Request.QueryString("SCID").ToString
            End If
        End Sub
    #Region " Other MethoDisplayInProfile "
        Private Function ValidateFilter() As MZKForm.MZKErrorBuilder

            Dim EBOFilterOBJ As New MZKForm.MZKErrorBuilder
            If Len(UCDateFrom.getDate().Trim()) > 0 Or Len(UCDateTo.getDate().Trim()) > 0 Then
                If (Len(UCDateFrom.getDate().Trim()) > 0 And Len(UCDateTo.getDate().Trim()) <= 0) Then
                    EBOFilterOBJ.AddError("Date TO should be selected", UCDateTo)

                ElseIf (Len(UCDateTo.getDate().Trim()) > 0 And Len(UCDateFrom.getDate().Trim()) <= 0) Then
                    EBOFilterOBJ.AddError("Date FROM should be selected", UCDateTo)

                ElseIf Convert.ToDateTime(UCDateFrom.getDate()) > Convert.ToDateTime(UCDateTo.getDate()) Then
                    EBOFilterOBJ.AddError("Date TO should be greater than Date FROM", UCDateTo)

                Else
                    EBOFilterOBJ.ClearErrorMessage()
                End If
            End If
        End Function
        Private Function GetFilterString() As String
            Dim sb As New StringBuilder

            If Not ddlScheduleCalendar.SelectedValue = "" AndAlso ddlScheduleCalendar.SelectedValue > 0 Then
                sb.AppendFormat(" And SC.SC_ID = '{0}' ", ddlScheduleCalendar.SelectedValue)
            End If
            If Not ddlWeekDay.SelectedValue = "" AndAlso Not ddlWeekDay.SelectedValue = "-1" Then
                sb.AppendFormat(" And DATENAME(dw, SCD.DateItem) = '{0}' ", ddlWeekDay.SelectedValue)
            End If
            If Not ddlDayType.SelectedValue = "" AndAlso Not ddlDayType.SelectedValue = "-1" Then
                sb.AppendFormat(" And SCD.HolidayType = '{0}' ", ddlDayType.SelectedValue)
            End If
            If txtFTEValue.Text.Length > 0 Then
                sb.AppendFormat(" And SCD.DefaultFTEValue = '{0}' ", txtFTEValue.Text)
            End If
            If txtHoliday.Text.Length > 0 Then
                sb.AppendFormat(" And CP.CALPName like '%{0}%' ", SQLInjectionHandler.GetEncodedString(txtHoliday.Text, True))
            End If
            If Not datadefAttConfigGroup_ID.DataDefinitionDropDownList.SelectedValue = "" AndAlso datadefAttConfigGroup_ID.DataDefinitionDropDownList.SelectedValue > 0 Then
                sb.AppendFormat(" And SCD.AttConfigGroup_ID = '{0}' ", datadefAttConfigGroup_ID.DataDefinitionDropDownList.SelectedValue)
            End If

            If rblADAExcluded.SelectedIndex > -1 Then
                Select Case rblADAExcluded.SelectedValue
                    Case "1" 'yes
                        sb.Append(" And ISNULL(SCD.ADAExclude, 0)=1 ")

                    Case "2" 'no
                        sb.Append(" And ISNULL(SCD.ADAExclude, 0)=0 ")
                End Select
            End If
            If rblStudentHoliday.SelectedIndex > -1 Then
                Select Case rblStudentHoliday.SelectedValue
                    Case "1" 'yes
                        sb.Append(" And ISNULL(SCD.StudentHoliday, 0)=1 ")

                    Case "2" 'no
                        sb.Append(" And ISNULL(SCD.StudentHoliday, 0)=0 ")
                End Select
            End If
            If rblStaffHoliday.SelectedIndex > -1 Then
                Select Case rblStaffHoliday.SelectedValue
                    Case "1" 'yes
                        sb.Append(" And ISNULL(SCD.StaffHoliday, 0)=1 ")

                    Case "2" 'no
                        sb.Append(" And ISNULL(SCD.StaffHoliday, 0)=0 ")
                End Select
            End If
            If rblStudentHalfDay.SelectedIndex > -1 Then
                Select Case rblStudentHalfDay.SelectedValue
                    Case "1" 'yes
                        sb.Append(" And ISNULL(SCD.StudentHalfDay, 0)=1 ")

                    Case "2" 'no
                        sb.Append(" And ISNULL(SCD.StudentHalfDay, 0)=0 ")
                End Select
            End If
            If rblStaffHalfDay.SelectedIndex > -1 Then
                Select Case rblStaffHalfDay.SelectedValue
                    Case "1" 'yes
                        sb.Append(" And ISNULL(SCD.StaffHalfDay, 0)=1 ")

                    Case "2" 'no
                        sb.Append(" And ISNULL(SCD.StaffHalfDay, 0)=0 ")
                End Select
            End If
            Dim EBOFilterOBJ As New MZKForm.MZKErrorBuilder
            If Len(UCDateFrom.getDate().Trim()) > 0 Or Len(UCDateTo.getDate().Trim()) > 0 Then
                If (Len(UCDateFrom.getDate().Trim()) > 0 And Len(UCDateTo.getDate().Trim()) <= 0) Then
                    EBOFilterOBJ.AddError("Date TO should be selected", UCDateTo)

                    ShowInfoPanel(EBOFilterOBJ.GetErrorMessage, True, True)
                ElseIf (Len(UCDateTo.getDate().Trim()) > 0 And Len(UCDateFrom.getDate().Trim()) <= 0) Then
                    EBOFilterOBJ.AddError("Date FROM should be selected", UCDateTo)

                    ShowInfoPanel(EBOFilterOBJ.GetErrorMessage, True, True)
                ElseIf Convert.ToDateTime(UCDateFrom.getDate()) > Convert.ToDateTime(UCDateTo.getDate()) Then
                    EBOFilterOBJ.AddError("Date TO should be greater than Date FROM", UCDateTo)

                    ShowInfoPanel(EBOFilterOBJ.GetErrorMessage, True, True)
                Else
                    If Len(UCDateFrom.getDate().Trim()) > 0 AndAlso Len(UCDateTo.getDate().Trim()) > 0 Then
                        EBOFilterOBJ.ClearErrorMessage()
                        ShowInfoPanel(EBOFilterOBJ.GetErrorMessage, False, False)
                        sb.Append(" And ISNULL(SCD.DateItem, 0)>='" + UCDateFrom.getDate() + "' AND ISNULL(SCD.DateItem, 0)<='" + UCDateTo.getDate() + "' ")
                    End If
                End If
            End If
            If sb.ToString.Length > 3 Then
                Return sb.ToString.Substring(4)
            Else
                Return String.Empty
            End If
        End Function
    #End Region

        Private Sub gvSchedule_PageSizeChanged(sender As Object, e As GridPageSizeChangedEventArgs) Handles gvSchedule.PageSizeChanged
            SaveData()
            gvSchedule.Rebind()
        End Sub

        Private Sub gvSchedule_PageIndexChanged(sender As Object, e As GridPageChangedEventArgs) Handles gvSchedule.PageIndexChanged
            SaveData()

            Dim c As Control = GetPostBackControl(Me.Page)
            If c IsNot Nothing AndAlso Not TryCast(c, LinkButton) Is Nothing AndAlso TryCast(c, LinkButton).CommandArgument IsNot Nothing AndAlso Not TryCast(c, LinkButton).CommandArgument = "" Then
                PageIndex = CType(DirectCast(c, LinkButton).CommandArgument, Integer) - 1
            ElseIf c IsNot Nothing AndAlso Not TryCast(c, Button) Is Nothing AndAlso TryCast(c, Button).CommandArgument IsNot Nothing AndAlso Not TryCast(c, Button).CommandArgument = "" Then
                Dim intPageIndex As Integer = 0
                If TryCast(c, Button).CommandArgument = "Next" Then
                    intPageIndex = DirectCast(sender, RadGrid).MasterTableView.CurrentPageIndex + 1
                ElseIf TryCast(c, Button).CommandArgument = "Prev" Then
                    intPageIndex = DirectCast(sender, RadGrid).MasterTableView.CurrentPageIndex - 1
                ElseIf TryCast(c, Button).CommandArgument = "First" Then
                    intPageIndex = 0
                ElseIf TryCast(c, Button).CommandArgument = "Last" Then
                    intPageIndex = GetValueBeforeDecimal(DirectCast(sender, RadGrid).MasterTableView.VirtualItemCount / DirectCast(sender, RadGrid).MasterTableView.PageSize) '+ 1
                End If
                PageIndex = intPageIndex
            End If

            If Not PageIndex = "" Then
                DirectCast(sender, RadGrid).MasterTableView.CurrentPageIndex = PageIndex '' DirectCast(sender, RadGrid).CurrentPageIndex
            Else
                DirectCast(sender, RadGrid).MasterTableView.CurrentPageIndex = 0
            End If

            gvSchedule.Rebind()
        End Sub
        Public Function GetValueBeforeDecimal(inputValue As String) As String
            Dim s As String = inputValue.ToString(CultureInfo.InvariantCulture) '.Split('.')
            Dim parts As String() = s.Split("."c)
            Dim i1 As Integer = Integer.Parse(parts(0))
            Dim i2 As Integer = Integer.Parse(parts(1))
            Return i1
        End Function
        Public Shared Function GetPostBackControl(page As Page) As Control
            Dim control As Control = Nothing
            Dim ctrlname As String = page.Request.Params.[Get]("__EVENTTARGET")
            If ctrlname IsNot Nothing AndAlso ctrlname <> [String].Empty Then

                control = page.FindControl(ctrlname)
            Else
                For Each ctl As String In page.Request.Form
                    Dim c As Control = page.FindControl(ctl)
                    If TypeOf c Is System.Web.UI.WebControls.Button Or TypeOf c Is System.Web.UI.WebControls.LinkButton Then
                        control = c
                        Exit For
                    End If

                Next
            End If
            Return control
        End Function
    End Class

Back to Top
UI for ASP.NET Ajax is Ready for VS 2017