Click here to Skip to main content
15,888,238 members
Home / Discussions / ASP.NET
   

ASP.NET

 
AnswerRe: How to avoid duplicate data insertion in.net???? Pin
Afzaal Ahmad Zeeshan17-Aug-14 2:48
professionalAfzaal Ahmad Zeeshan17-Aug-14 2:48 
AnswerRe: How to avoid duplicate data insertion in.net???? Pin
NishantRaval27-Aug-14 23:32
NishantRaval27-Aug-14 23:32 
AnswerRe: How to avoid duplicate data insertion in.net???? Pin
Sibeesh KV29-Sep-14 1:36
professionalSibeesh KV29-Sep-14 1:36 
Questionhow to enable false of iframe page in asp.net not display false by jquery and css? Pin
kp 77715-Aug-14 4:54
professionalkp 77715-Aug-14 4:54 
AnswerRe: how to enable false of iframe page in asp.net not display false by jquery and css? Pin
ZurdoDev15-Aug-14 5:28
professionalZurdoDev15-Aug-14 5:28 
QuestionRequiredfield validator is not working Pin
murali_utr14-Aug-14 18:47
murali_utr14-Aug-14 18:47 
AnswerRe: Requiredfield validator is not working Pin
ZurdoDev15-Aug-14 5:29
professionalZurdoDev15-Aug-14 5:29 
QuestionHow to display certain records if user's search comes up empty? Pin
samflex14-Aug-14 6:20
samflex14-Aug-14 6:20 
Hello Experts,

We are building an app that allows users to make online reservations of our facility.

The code below is designed to allow users to perform a search by either specific date or by date range.

Users can also search by selecting a search option from the dropdownlist.


The way the code works currently, if user's search turns up nothing, then we get the following error message:

Object reference not set to an instance of an object.

Line 259: Dim lblcurrentpage As Label = DirectCast(gvrow.Cells(0).FindControl("CurrentPage"), Label)


Rather than the error message, w would like the code to work differently.

If user's search is successful, the results of his/her search is displayed.

If however, no data is found based on his or her search parameter, we would like to display one month's worth of results.

Is this possible?

Below is the current code we are using.

PHP
Private Sub showGrid()
    ' Set the value of the SearchString so it gets
    SearchString = txtSpecificDate.Text
    ViewSelect = Request("ViewBy")

    If ViewSelect = "" Or ViewSelect = "Range" Then
        ViewSelect = "Range"
    Else
        ViewSelect = "Specific"

    End If
    'Response.Write(ViewSelect)
    'Response.End()

    Dim strQuery As String
    Dim strSearch As String
    Dim receiveddate As String = txtSpecificDate.Text
    Dim fromdate As String = txtFromDate.Text
    Dim enddate As String = txtToDate.Text
    ' Dim dts As DateTime = DateTime.ParseExact(DateString, "MM/dd/yyyy", CultureInfo.InvariantCulture)
    'Protect against SQL Injection
    strSearch = Replace(receiveddate, "'", "''", 1, -1, 1)
    fromdate = Replace(fromdate, "'", "''", 1, -1, 1)
    enddate = Replace(enddate, "'", "''", 1, -1, 1)

    receiveddate = DateTime.Today.ToString("MM/dd/yyyy")
    fromdate = DateTime.Today.ToString("MM/dd/yyyy")
    enddate = "12/31/2050"
    ' first: Do we use AND or OR between clauses in the WHERE?
    Dim andors As String = ANDOR.SelectedValue

    'Response.Write(andors)
    'Response.End()

    ' and now build up the WHERE.

    'First, initialize where just to make sure it has nothing prior to our search
    Dim where As String
    where = ""

    Dim facilityT As DropDownList
    facilityT = FindControl("DropDownList1")
    If facilityT.SelectedValue <> "" Then
        If where <> "" Then where = where & andors
        where = " i.instructorName = '" & Replace(facilityT.SelectedValue, "'", "''") & "'"
    End If
    If ViewSelect = "Range" Then
        If where <> "" Then where = where & andors
        where = where & " CONVERT(VARCHAR(10), d.trainingDates, 101) >= '" & fromdate & "' AND CONVERT(VARCHAR(10),  d.trainingDates, 101) < '" & (enddate) & "'"
    End If
    If ViewSelect = "Specific" Then
        If where <> "" Then where = where & andors
        where = where & " CONVERT(VARCHAR(10), d.trainingDates, 101) = '" & strSearch & "' "
    End If
    'Response.Write(where)
    'Response.End()

    strQuery = "SELECT L.LocationId," & _
   "c.courseId, " & _
    "c.coursename, " & _
   "CASE WHEN L.Seating_Capacity - COALESCE(TS.TakenSeats,0) = 0 THEN 'Not Available' " & _
       " ELSE 'Available' END AS 'AvailableSeats'," & _
    "d.dateid, " & _
   " d.trainingDates, " & _
    "d.trainingtime, " & _
   " c.CourseDescription, " & _
   " i.instructorName, " & _
    "l.location " & _
  " FROM tblLocations L " & _
  " Inner Join tblCourses c on l.locationId = c.locationId " & _
  " Inner Join tblTrainingDates d on c.dateid=d.dateid " & _
 "  Inner Join tblCourseInstructor ic on c.courseId = ic.CourseId " & _
 "  Inner Join tblInstructors i on ic.instructorId = i.instructorId " & _
 "  OUTER APPLY (Select Count(*) TakenSeats " & _
 "  FROM tblTrainings T " & _
 "  where(L.LocationId = T.LocationId) " & _
 "  AND c.courseId = t.courseId) TS where " & where
    'Response.Write("DEBUG: " & strQuery & "<HR>")
    'Response.End()
    Dim cmd As New SqlCommand(strQuery)
    Dim dt As DataTable = GetData(cmd)

    If dt.Rows.Count = 0 Then

        message.Text = "No Records Found"
    End If

    GridView1.DataSource = dt
    GridView1.DataBind()
End Sub


Thanks a lot in advance for your assistance.
SuggestionRe: How to display certain records if user's search comes up empty? Pin
Richard Deeming14-Aug-14 6:45
mveRichard Deeming14-Aug-14 6:45 
GeneralRe: How to display certain records if user's search comes up empty? Pin
samflex14-Aug-14 7:01
samflex14-Aug-14 7:01 
GeneralRe: How to display certain records if user's search comes up empty? Pin
Richard Deeming14-Aug-14 7:28
mveRichard Deeming14-Aug-14 7:28 
GeneralRe: How to display certain records if user's search comes up empty? Pin
samflex14-Aug-14 17:07
samflex14-Aug-14 17:07 
GeneralRe: How to display certain records if user's search comes up empty? Pin
Richard Deeming18-Aug-14 2:02
mveRichard Deeming18-Aug-14 2:02 
GeneralRe: How to display certain records if user's search comes up empty? Pin
samflex18-Aug-14 2:54
samflex18-Aug-14 2:54 
GeneralRe: How to display certain records if user's search comes up empty? Pin
Richard Deeming18-Aug-14 7:15
mveRichard Deeming18-Aug-14 7:15 
GeneralRe: How to display certain records if user's search comes up empty? Pin
samflex18-Aug-14 8:04
samflex18-Aug-14 8:04 
GeneralRe: How to display certain records if user's search comes up empty? Pin
Richard Deeming18-Aug-14 8:38
mveRichard Deeming18-Aug-14 8:38 
GeneralRe: How to display certain records if user's search comes up empty? Pin
samflex18-Aug-14 10:55
samflex18-Aug-14 10:55 
QuestionAJAX control Pin
murali_utr13-Aug-14 23:09
murali_utr13-Aug-14 23:09 
GeneralRe: AJAX control Pin
Kornfeld Eliyahu Peter13-Aug-14 23:18
professionalKornfeld Eliyahu Peter13-Aug-14 23:18 
GeneralRe: AJAX control Pin
murali_utr14-Aug-14 18:00
murali_utr14-Aug-14 18:00 
QuestionGet original string from Guid Pin
Member 947380913-Aug-14 19:06
Member 947380913-Aug-14 19:06 
AnswerRe: Get original string from Guid Pin
Bernhard Hiller13-Aug-14 21:57
Bernhard Hiller13-Aug-14 21:57 
AnswerRe: Get original string from Guid Pin
Kornfeld Eliyahu Peter13-Aug-14 22:27
professionalKornfeld Eliyahu Peter13-Aug-14 22:27 
AnswerRe: Get original string from Guid Pin
Richard MacCutchan13-Aug-14 22:28
mveRichard MacCutchan13-Aug-14 22:28 

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.