Click here to Skip to main content
15,910,603 members
Home / Discussions / ASP.NET
   

ASP.NET

 
QuestionVcard Reading in Asp.net Pin
dwadasi11-Apr-09 0:57
dwadasi11-Apr-09 0:57 
QuestionHow to access the changes in style.display property by Javascript in code behind Pin
prashantkharade11-Apr-09 0:39
prashantkharade11-Apr-09 0:39 
AnswerRe: How to access the changes in style.display property by Javascript in code behind Pin
Yusuf11-Apr-09 17:29
Yusuf11-Apr-09 17:29 
QuestionRe: How to access the changes in style.display property by Javascript in code behind Pin
prashantkharade12-Apr-09 17:46
prashantkharade12-Apr-09 17:46 
AnswerRe: How to access the changes in style.display property by Javascript in code behind [modified] Pin
PauloCastilho13-Apr-09 10:05
PauloCastilho13-Apr-09 10:05 
QuestionErroor: The state information is invalid for this page and might be corrupted. Pin
keyur satyadev11-Apr-09 0:08
keyur satyadev11-Apr-09 0:08 
AnswerRe: Erroor: The state information is invalid for this page and might be corrupted. Pin
Yusuf11-Apr-09 17:31
Yusuf11-Apr-09 17:31 
QuestionGridView Sorting with ObjectDataSource Issues Pin
mazen9710-Apr-09 23:49
mazen9710-Apr-09 23:49 
Guys,


I'm developed a quiet complex searh page for my company and produced the results in a datagrid.

I'm following N-Tier structure so I have a view model (SortSearch.aspx), Business Logic (SortSearchManagement.vb) and Data Access Layer (SortsearchDA.vb).

I created ObjectDataSource that is getting list of objects (SearchResultEntity) and the searching conditions are stored in a session as well as sortingexpression, sorting direction and others as it shows below

<asp:ObjectDataSource ID="SearchResultsObjectDataSource" runat="server" 
        SelectMethod="getRequests" TypeName="ATVS.Initiation.BLL.SortSearchManager" 
        SortParameterName="SortExpression">
        <SelectParameters>
            <asp:SessionParameter Name="searchCriteria" SessionField="SearchCriteria" 
                Type="Object" />
            <asp:SessionParameter DefaultValue="" Name="SearchType" SessionField="TYPE" 
                Type="String" />
            <asp:SessionParameter Name="UserGroup" SessionField="USERGROUP" Type="Int32" />
            <asp:SessionParameter Name="SortExpression" SessionField="SortExpression" 
                Type="String" />
            <asp:SessionParameter Name="SortDirection" SessionField="SortDirestion" 
                Type="Int32" />
        </SelectParameters>
    </asp:ObjectDataSource>



The grid contains multiple columns and some of its columns contains buttons and hyperlink as shown below:

<asp:GridView ID="resultsGrid" runat="server" AllowPaging="True" 
        AutoGenerateColumns="False" 
        DataSourceID="SearchResultsObjectDataSource" CssClass="grid" 
        AllowSorting="True">
        <Columns>
            <asp:HyperLinkField DataNavigateUrlFields="ARID" DataNavigateUrlFormatString="/LastResponse.aspx?ARID={0}"
                            HeaderText="ARID" Target="_blank" DataTextField="ARID" 
                SortExpression="ARID">
                <HeaderStyle CssClass="groupHeading" />
            </asp:HyperLinkField>
            <asp:BoundField DataField="InitiatorName" HeaderText="Initiator Name" 
                SortExpression="INITIATOR_LOGIN" >
                <HeaderStyle CssClass="groupHeading" />
            </asp:BoundField>
            <asp:BoundField DataField="LloydeNo" HeaderText="Lloyde #" 
                SortExpression="LLOYDS_NBR" >
                <HeaderStyle CssClass="groupHeading" />
            </asp:BoundField>
            <asp:BoundField DataField="TankerName" HeaderText="Tanker Name" 
                SortExpression="CURRENT_NAME" >
                <HeaderStyle CssClass="groupHeading" />
            </asp:BoundField>
            <asp:BoundField DataField="Port" HeaderText="Port" SortExpression="PORT_NAME" >
                <HeaderStyle CssClass="groupHeading" />
            </asp:BoundField>
            <asp:BoundField DataField="InitiationDate" HeaderText="Initiation Date" 
                SortExpression="created_date" >
                <HeaderStyle CssClass="groupHeading" />
            </asp:BoundField>
            <asp:BoundField DataField="Status" HeaderText="Status" 
                SortExpression="REQUEST_STATUS_NAME" >
                <HeaderStyle CssClass="groupHeading" />
            </asp:BoundField>
            <asp:BoundField DataField="EvaluatorName" HeaderText="Evaluator Name" 
                SortExpression="EVALUATOR" >
                <HeaderStyle CssClass="groupHeading" />
            </asp:BoundField>
            <asp:BoundField DataField="DaysLeft" HeaderText="Days Left" 
                SortExpression="EXPIRATION_DATE" >
                <HeaderStyle CssClass="groupHeading" />
            </asp:BoundField>
            <asp:BoundField DataField="Expirydate" HeaderText="Expiry Date" 
                SortExpression="EXPIRATION_DATE" >
                <HeaderStyle CssClass="groupHeading" />
            </asp:BoundField>
            <asp:ButtonField ButtonType="Button" CommandName="Select_Override" 
                Text="Override" >
                <ControlStyle CssClass="button" />
            </asp:ButtonField>
            <asp:ButtonField ButtonType="Button" CommandName="Select_Followup" 
                Text="Follow Up" >
                <ControlStyle CssClass="button" />
            </asp:ButtonField>
            <asp:ButtonField ButtonType="Button" CommandName="Cancel" Text="Cancel" >
                <ControlStyle CssClass="button" />
            </asp:ButtonField>
            <asp:BoundField DataField="InitiatorGroup" 
                SortExpression="InitiatorGroup" />
            <asp:BoundField DataField="StatusID" SortExpression="StatusID" />
            <asp:BoundField DataField="IsInitiatorReply" 
                SortExpression="IsInitiatorReply" />
        </Columns>
        <FooterStyle HorizontalAlign="Center" />
        <HeaderStyle CssClass="groupHeading" />
    </asp:GridView>


I turned autosorting on and wrote a cutomized sorting event as shown below


Protected Sub resultsGrid_Sorting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewSortEventArgs) Handles resultsGrid.Sorting
    Session("SortDirestion") = CInt(e.SortDirection)
    Session("SortExpression") = e.SortExpression.ToString()
    resultsGrid.DataBind()
End Sub


I have two issues:


1. The session value SortExpression is passing nothing to Data Access Layer? While it is passing all others?
2. Once I click on a column header every thing went well but once the grid is rendering it disappears?!!

Here is the Page load event for the aspx file
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If IsNothing(Session("USERGROUP")) Then
            Response.Redirect("Default.aspx")
        End If
        Session("TYPE") = Request.QueryString("TYPE")

        resultsGrid.Visible = False
        If Session("TYPE") = "" Then
            Session("TYPE") = "ALL"
        End If
        Dim type As String = Session("TYPE")
        If type.Equals("FOLLOWUP") Or type.Equals("OVERRIDE") Then
            statusDropDownList.Visible = False
            StatusLabel.Visible = False
        End If
        If Not IsPostBack Then
            Session("SortDirestion") = 0
            Session("SortExpression") = "ARID"
        End If
    End Sub


Here are all events for GridView control
Protected Sub resultsGrid_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles resultsGrid.PageIndexChanging
        resultsGrid.PageIndex = e.NewPageIndex
        'resultsGrid.DataBind()
        startSearch()
    End Sub

Private Sub resultsGrid_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles resultsGrid.PreRender
        If resultsGrid.Rows.Count = 0 Then
            ErrLabel.Visible = True
            ErrLabel.Text = "There is no result matching your search criteria"
        Else
            ErrLabel.Visible = False
        End If
        'If Results.Count &gt; 0 Then
        populateResultGrid(Session("USERGROUP"))
        'End If
    End Sub

Protected Sub resultsGrid_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles resultsGrid.RowCommand
        Dim x As Integer = 0
        If e.CommandName.Equals("Select_Override") Then
            x = CInt(e.CommandArgument)
            Dim HyperLinkFromGrid As New HyperLink
            HyperLinkFromGrid = resultsGrid.Rows(x).Cells(0).Controls(0)
            Dim ARID As String = HyperLinkFromGrid.Text
            Session("ARID") = ARID
            Session("PORT") = resultsGrid.Rows(x).Cells.Item(4).Text
            Session("OverrideDataTableCreationFlag") = False
            Session("CurrentReqStatusID") = CInt(resultsGrid.Rows(x).Cells.Item(resultsGrid.Columns.Count - 2).Text)
            'Destroy all Sessions
            Session("TYPE") = Nothing
            Session("SearchCriteria") = Nothing
            Response.Redirect("Override_Request.aspx")
        ElseIf e.CommandName.Equals("Select_Followup") Then
            x = CInt(e.CommandArgument)
            Dim HyperLinkFromGrid As New HyperLink
            HyperLinkFromGrid = resultsGrid.Rows(x).Cells(0).Controls(0)
            Dim ARID As String = HyperLinkFromGrid.Text
            Session("ARID") = ARID
            Session("PORT") = resultsGrid.Rows(x).Cells.Item(4).Text
            Dim status As Integer = CInt(resultsGrid.Rows(x).Cells.Item(14).Text)
            'Destroy all Sessions
            Session("TYPE") = Nothing
            Session("SearchCriteria") = Nothing
            If status = 3 Then
                Response.Redirect("Followup_Request.aspx")
            ElseIf status = 9 Then
                Response.Redirect("OverrideFollowupRequest.aspx")
            End If
        ElseIf e.CommandName.Equals("Cancel") Then
            x = CInt(e.CommandArgument)
            Dim HyperLinkFromGrid As New HyperLink
            HyperLinkFromGrid = resultsGrid.Rows(x).Cells(0).Controls(0)
            Dim ARID As String = HyperLinkFromGrid.Text
            Session("ARID") = ARID
            'Destroy all Sessions
            Session("TYPE") = Nothing
            Session("SearchCriteria") = Nothing
            Response.Redirect("CancelRequest.aspx")
        End If
    End Sub



Here is the data access layer class

Imports System.Data.OracleClient
Imports ATVS.Initiation.Entities
Imports Microsoft.ApplicationBlocks.Data
Imports Microsoft.ApplicationBlocks.ExceptionManagement

Public Class SortSearchDA
    Public Function SearchRequests(ByVal searchCriteria As SearchCriteria, ByVal SortExpression As String, ByVal SortDirection As Integer) As List(Of SearchResults)
        Dim searchs As New List(Of SearchResults)
        Try
            Dim SQLStr As String = ""
            SQLStr = PrepareSelectStatement(SQLStr, searchCriteria)
            If Not SortExpression.Equals(String.Empty) Then
                SQLStr += " ORDER BY " + SortExpression + " "
                If SortDirection = 0 Then
                    SQLStr += "ASC"
                Else
                    SQLStr += "DESC"
                End If
            End If
            Dim dsResult As New System.Data.DataSet
            dsResult = OracleHelper.ExecuteDataset(StoredProcedure.strConnection, CommandType.Text, SQLStr)
            Dim tbl As DataTable = dsResult.Tables(0)
            For Each row As DataRow In tbl.Rows
                Dim search As New SearchResults
                Dim dsGroup As New DataSet
                search = prepareSearchEntity(row)
                Dim SQLStr2 As String = "SELECT DISTINCT RE.ROLE_ID FROM T_RTT_TVS_ROLE_EMPLOYEE RE WHERE RE.VTMS_ROLE_OR_LOGIN='" + search.InitiatorName.ToUpper() + "'"
                dsGroup = OracleHelper.ExecuteDataset(StoredProcedure.strConnection, CommandType.Text, SQLStr2)
                Dim table As New DataTable
                table = dsGroup.Tables(0)
                If dsGroup.Tables(0).Rows.Count &gt; 0 Then
                    search.InitiatorGroup = CInt(dsGroup.Tables(0).Rows(0).Item(0).ToString())
                End If
                searchs.Add(search)
            Next
        Catch ex As ApplicationException

        End Try
        Return searchs
    End Function

Private Function PrepareSelectStatement(ByVal SQLStr As String, ByVal searchCriteria As SearchCriteria) As String
        SQLStr = "SELECT DISTINCT ar.ARID,ar.INITIATOR_LOGIN,ar.LLOYDS_NBR,TAN.DEADWT_TONNAGE,TAN.CURRENT_NAME,ar.SUBMITTEDDATE created_date,ar.REQUEST_STATUS_ID,"
        SQLStr += "ars.REQUEST_STATUS_NAME,ar.EXPIRATION_DATE, ar.EVALUATOR,"
        SQLStr += "( (CASE WHEN (V.TVS_ACC_ID > 0 OR AR.EXPIRATION_DATE &lt; SYSDATE) THEN 'EXPIRED'"
        SQLStr += "ELSE DECODE(AR.REQUEST_STATUS_ID, 4,'VALID') END)) AS STATUS,"
        SQLStr += "( (CASE WHEN (V.TVS_ACC_ID > 0 OR AR.EXPIRATION_DATE < SYSDATE) THEN ''"
        SQLStr += "ELSE DECODE(AR.REQUEST_STATUS_ID, 3,'Follow up') END)) AS DISPLAY_TEXT,"
        SQLStr += "planned.SAUDI_PORT_CODE,port.PORT_NAME,ars.REQUEST_STATUS_NAME AS STATUS_NAME, AR.YN_INITIATOR_REPLY"
        SQLStr += " FROM   RTTDBA.T_RTT_ACCEPTANCE_REQUEST ar,RTTDBA.T_RTT_ACCEPTANC_REQUEST_STATUS ars,RTTDBA.T_RTT_TANKER TAN,"
        SQLStr += "RTTDBA.T_RTT_VISIT V,RTTDBA.T_RTT_PLANNED_VISIT planned, RTTDBA.T_RTT_SAUDI_PORT port"
        SQLStr += " WHERE  ar.REQUEST_STATUS_ID = ars.REQUEST_STATUS_ID AND"
        SQLStr += " ar.LLOYDS_NBR = TAN.LLOYDS_NBR AND"
        SQLStr += " V.TVS_ACC_ID(+) = AR.ARID AND"
        SQLStr += " planned.SAUDI_PORT_CODE = port.SAUDI_PORT_CODE AND"
        SQLStr += " ar.ARID ="
        If searchCriteria.ARID = 0 Then
            SQLStr += "ar.ARID"
        Else
            SQLStr += searchCriteria.ARID.ToString()
        End If
        SQLStr += " AND planned.ARID = ar.ARID"
        SQLStr += " AND ar.LLOYDS_NBR ="
        If searchCriteria.LloydsNo = 0 Then
            SQLStr += "ar.LLOYDS_NBR "
        Else
            SQLStr += searchCriteria.LloydsNo.ToString()
        End If
        SQLStr += " AND ar.MODIFIED_DATE >="
        If searchCriteria.InitiationDateFrom.Equals(CDate("1/1/1900")) Then
            SQLStr += "ar.MODIFIED_DATE"
        Else
            SQLStr += searchCriteria.InitiationDateFrom.ToString()
        End If
        SQLStr += " AND ar.MODIFIED_DATE <="
        If searchCriteria.InitiationDateTo.Equals(CDate("1/1/1900")) Then
            SQLStr += "ar.MODIFIED_DATE"
        Else
            SQLStr += searchCriteria.InitiationDateTo.ToString()
        End If
        SQLStr += " AND lower(ar.INITIATOR_LOGIN) LIKE '%'||"
        If searchCriteria.InitiatorName.Equals(String.Empty) Then
            SQLStr += "lower(ar.INITIATOR_LOGIN)||'%'"
        Else
            SQLStr += "lower(" + searchCriteria.InitiatorName + ")||'%'"
        End If

        SQLStr += " AND ars.REQUEST_STATUS_ID ="
        If searchCriteria.Status = 0 Then
            SQLStr += "ars.REQUEST_STATUS_ID"
        Else
            SQLStr += searchCriteria.Status
        End If
        SQLStr += " AND lower(TAN.CURRENT_NAME) LIKE '%'||"
        If searchCriteria.TankerName.Equals(String.Empty) Then
            SQLStr += "lower(TAN.CURRENT_NAME)||'%'"
        Else
            SQLStr += "lower(" + searchCriteria.TankerName + ")||'%'"
        End If
        Return SQLStr
    End Function

    Public Function prepareNewRequestEntity(ByVal row As DataRow) As NewRequest
        Dim search As New NewRequest
        If Not IsDBNull(row) Then
            search.ARID = row("ARID")

            If row("EXPIRATION_DATE").Equals(DBNull.Value) Then
                'do nothing
            Else
                search.ExpiryDate = row("EXPIRATION_DATE")
            End If

            search.Tanker.LloydNum = row("LLOYDS_NBR")
            search.PortNCargo.SaudiPortCodeName = row("PORT_NAME")
            search.Status = row("REQUEST_STATUS_NAME")
            search.Tanker.TankerName = row("CURRENT_NAME")
        End If
        Return search
    End Function
End Class



and last but not least the Business Logic Layer
Imports ATVS.Common
Imports ATVS.Initiation.Entities
Imports ATVS.Initiation.DAL
Imports ATVS.Initiation.DAL.TnakerInfoDA
Public Class SortSearchManager
    Public Function getRequests(ByVal searchCriteria As SearchCriteria, ByVal SearchType As String, ByVal UserGroup As Integer, ByVal SortExpression As String, ByVal SortDirection As Integer) As List(Of SearchResults)
        Dim results As New List(Of SearchResults)
        Dim Search As New SortSearchDA
        If SearchType = "" Then
            Return results
        End If
        results = Search.SearchRequests(searchCriteria, SortExpression, SortDirection)
        'Apply filtering if user group is basic
        If UserGroup = UserRole.INITIATOR_BASIC Then
            results = FilterSearch(results, UserGroup)
        End If
        'Apply Filtering if the search is by override or followup
        If SearchType.Equals("OVERRIDE") Or SearchType.Equals("FOLLOWUP") Then
            results = FilterSearch(results, SearchType, searchCriteria)
        End If

        'results(0).DaysLeft = results(0).Expirydate.Day - results(0).InitiationDate.Day
        Return results
    End Function
    Private Function FilterSearch(ByVal results As List(Of SearchResults), ByVal SearchType As String, ByVal searchCriteria As SearchCriteria) As List(Of SearchResults)
        Dim TempResults As New List(Of SearchResults)
        If SearchType.Equals("OVERRIDE") Then
            For Each result As SearchResults In results
                If result.StatusID = 4 Or result.StatusID = 5 Or result.StatusID = 6 Then
                    If searchCriteria.InitiationDateFrom.Equals(CDate("1/1/1900")) And searchCriteria.InitiationDateTo.Equals(CDate("1/1/1900")) Then
                        If Not result.InitiationDate &lt; Now.AddMonths(-1) Then
                            TempResults.Add(result)
                        End If
                    Else
                        TempResults.Add(result)
                    End If
                End If
            Next
        ElseIf SearchType.Equals("FOLLOWUP") Then
            For Each result As SearchResults In results
                If result.StatusID = 3 Or result.StatusID = 9 Then
                    If searchCriteria.InitiationDateFrom.Equals(CDate("1/1/1900")) And searchCriteria.InitiationDateTo.Equals(CDate("1/1/1900")) Then
                        If Not result.InitiationDate < Now.AddMonths(-1) Then
                            TempResults.Add(result)
                        End If
                    Else
                        TempResults.Add(result)
                    End If
                End If
            Next
        End If
        results = New List(Of SearchResults)
        results = TempResults
        Return results
    End Function
    Private Function FilterSearch(ByVal results As List(Of SearchResults), ByVal UserGroup As Integer) As List(Of SearchResults)
        Dim TempResults As New List(Of SearchResults)
        For Each Result As SearchResults In results
            If Result.InitiatorGroup = UserRole.INITIATOR_BASIC Then
                TempResults.Add(Result)
            End If
        Next
        Return TempResults
    End Function
End Class


Guys, Your help is highly appreciated and I'm sorry in advance for the amount of code I included but I would like to make it as clear as possible for every one.

I'm sorry also for my weak english Smile | :)

PS: I'm trying to find a way to sort the grid using ObjectDataSource for weeks and this is what I got and I'm new to all of this I'm originally a Java Developer !!

Mazen
QuestionAbout the masterpage in VS2008 Pin
Ethe1st10-Apr-09 21:34
Ethe1st10-Apr-09 21:34 
AnswerRe: About the masterpage in VS2008 Pin
Ramesh Swaminathan10-Apr-09 22:02
Ramesh Swaminathan10-Apr-09 22:02 
GeneralRe: About the masterpage in VS2008 [modified] Pin
Ethe1st11-Apr-09 3:11
Ethe1st11-Apr-09 3:11 
QuestionCreate Dynamic SiteMap Pin
slSoftware10-Apr-09 20:46
slSoftware10-Apr-09 20:46 
QuestionCom Port Problem , Modem ,Asp.Net ,Real IP Address. Pin
ketan d patel10-Apr-09 20:14
ketan d patel10-Apr-09 20:14 
AnswerRe: Com Port Problem , Modem ,Asp.Net ,Real IP Address. Pin
Zia Ul Haq Soofi11-Apr-09 1:15
Zia Ul Haq Soofi11-Apr-09 1:15 
GeneralRe: Com Port Problem , Modem ,Asp.Net ,Real IP Address. Pin
ketan d patel11-Apr-09 2:27
ketan d patel11-Apr-09 2:27 
QuestionVisual Studio 2008 Professional Office Components Pin
Distind10-Apr-09 10:11
Distind10-Apr-09 10:11 
QuestionPaging without Javascript Pin
Charmy310-Apr-09 7:28
Charmy310-Apr-09 7:28 
QuestionHELP - Forms Auth Cookie persists after closing browser... Pin
Grapes-R-Fun10-Apr-09 5:45
Grapes-R-Fun10-Apr-09 5:45 
QuestionRe: HELP - Forms Auth Cookie persists after closing browser... Pin
led mike10-Apr-09 7:54
led mike10-Apr-09 7:54 
AnswerRe: HELP - Forms Auth Cookie persists after closing browser... Pin
Grapes-R-Fun10-Apr-09 9:55
Grapes-R-Fun10-Apr-09 9:55 
GeneralRe: HELP - Forms Auth Cookie persists after closing browser... Pin
led mike10-Apr-09 10:05
led mike10-Apr-09 10:05 
QuestionHow to Store SWF files to SQL Server 2005 from C# WinForm Application and retrieve it and display in ASP.NET Web Page Pin
AARIFBANGI10-Apr-09 5:08
AARIFBANGI10-Apr-09 5:08 
AnswerRe: How to Store SWF files to SQL Server 2005 from C# WinForm Application and retrieve it and display in ASP.NET Web Page Pin
Colin Angus Mackay10-Apr-09 5:09
Colin Angus Mackay10-Apr-09 5:09 
GeneralRe: How to Store SWF files to SQL Server 2005 from C# WinForm Application and retrieve it and display in ASP.NET Web Page Pin
AARIFBANGI10-Apr-09 5:25
AARIFBANGI10-Apr-09 5:25 
GeneralRe: How to Store SWF files to SQL Server 2005 from C# WinForm Application and retrieve it and display in ASP.NET Web Page Pin
Colin Angus Mackay10-Apr-09 5:30
Colin Angus Mackay10-Apr-09 5:30 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.