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

ASP.NET

 
GeneralProblem when try export part of web page into word docment application Pin
smr851-Apr-08 16:01
smr851-Apr-08 16:01 
GeneralSing out user on session end [modified] Pin
AlexeiXX31-Apr-08 13:23
AlexeiXX31-Apr-08 13:23 
GeneralRe: Sing out user on session end Pin
Rocky#1-Apr-08 20:44
Rocky#1-Apr-08 20:44 
GeneralCustom Control problem in C# Pin
verlinden.nick@telenet.be1-Apr-08 9:55
verlinden.nick@telenet.be1-Apr-08 9:55 
GeneralRe: Custom Control problem in C# Pin
led mike1-Apr-08 10:00
led mike1-Apr-08 10:00 
GeneralRe: Custom Control problem in C# Pin
verlinden.nick@telenet.be1-Apr-08 10:09
verlinden.nick@telenet.be1-Apr-08 10:09 
GeneralRe: Custom Control problem in C# Pin
led mike1-Apr-08 10:53
led mike1-Apr-08 10:53 
GeneralNeed help with Datalist Edit Command Pin
AdamNThompson1-Apr-08 9:12
AdamNThompson1-Apr-08 9:12 
I need a little help with some code I'm working on. I have a Datalist control that is throwing the following expeption.

------------------------------------------------------------------------
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
------------------------------------------------------------------------

Here is my code.

<br />
Sub Edit_Command(ByVal sender As Object, ByVal e As DataListCommandEventArgs) Handles DataList.EditCommand<br />
<br />
        DataList.EditItemIndex = CType(e.Item.ItemIndex, Integer)<br />
<br />
        Dim strDate As String = ""<br />
        Dim strAssignments As String = ""<br />
        Dim strSchool As String = ""<br />
        Dim strProgramme As String = ""<br />
        Dim strSubject As String = ""<br />
        Dim strCity As String = ""<br />
        Dim strState As String = ""<br />
        Dim strReason As String = ""<br />
<br />
        Dim reader As SqlDataReader<br />
        Dim cmd As New SqlCommand("SELECT * FROM tblVolDeclinedMissedCanceledAssignments WHERE VolunteerId=" & VolunteerId() & " AND Id=" & e.CommandArgument, cn)<br />
        cmd.CommandType = Data.CommandType.Text<br />
<br />
        Try<br />
            cn.Open()<br />
            reader = cmd.ExecuteReader()<br />
<br />
            While reader.Read<br />
                strDate = IIf(IsDBNull(reader("Date")), "", reader("Date"))<br />
                strAssignments = IIf(IsDBNull(reader("Assignment")), "", reader("Assignment"))<br />
                strSchool = IIf(IsDBNull(reader("SchoolVenue")), "", reader("SchoolVenue"))<br />
                strProgramme = IIf(IsDBNull(reader("Programme")), "", reader("Programme"))<br />
                strSubject = IIf(IsDBNull(reader("Subject")), "", reader("Subject"))<br />
                strCity = IIf(IsDBNull(reader("City")), "", reader("City"))<br />
                strState = IIf(IsDBNull(reader("StateProvince")), "", reader("StateProvince"))<br />
                strReason = IIf(IsDBNull(reader("Reason")), "", reader("Reason"))<br />
            End While<br />
<br />
        Catch ex As Exception<br />
            Throw New ApplicationException(ex.Message)<br />
        Finally<br />
            cn.Close()<br />
        End Try<br />
<br />
        CType(e.Item.FindControl("rdpEditDate"), Telerik.WebControls.RadDatePicker).SelectedDate = strDate<br />
        CType(e.Item.FindControl("ddlEditAssignments"), DropDownList).SelectedValue = strAssignments<br />
        CType(e.Item.FindControl("txtEditSchoolVenue"), TextBox).Text = strSchool<br />
        CType(e.Item.FindControl("ddlEditProgramme"), DropDownList).SelectedValue = strProgramme<br />
        CType(e.Item.FindControl("ddlEditSubject"), DropDownList).SelectedValue = strSubject<br />
        CType(e.Item.FindControl("txtEditCity"), TextBox).Text = strCity<br />
        CType(e.Item.FindControl("ddlEditStateProvince"), DropDownList).SelectedValue = strState<br />
        CType(e.Item.FindControl("txtEditReason"), TextBox).Text = strReason<br />
        'Me.ddlEditAssignments.Items.FindByText(reader("Assignment")).Selected = True<br />
<br />
        LoadDataMSCAData()<br />
    End Sub<br />


The exception is thrown as soon as I hit the lines at the bottom where I am trying to assign the values from the datareader to the controls in the EditItemTemplate of the Datalist. What is really wierd about this is that I am using the exact same syntax to find the controls in my update command (below), and it works just fine.

Update Command:

<br />
Protected Sub DataList_UpdateCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataListCommandEventArgs) Handles DataList.UpdateCommand<br />
<br />
        Dim arg As String = e.CommandArgument<br />
<br />
        Dim strDate As String = CType(e.Item.FindControl("rdpEditDate"), Telerik.WebControls.RadDatePicker).SelectedDate.ToString<br />
        Dim strAssignment As String = CType(e.Item.FindControl("ddlEditAssignments"), DropDownList).SelectedValue<br />
        Dim strSchoolVenue As String = CType(e.Item.FindControl("txtEditSchoolVenue"), TextBox).Text<br />
        Dim strProgramme As String = CType(e.Item.FindControl("ddlEditProgramme"), DropDownList).SelectedValue<br />
        Dim strSubject As String = CType(e.Item.FindControl("ddlEditSubject"), DropDownList).SelectedValue<br />
        Dim strCity As String = CType(e.Item.FindControl("txtEditCity"), TextBox).Text<br />
        Dim strStateProvince As String = CType(e.Item.FindControl("ddlEditStateProvince"), DropDownList).SelectedValue<br />
        Dim strReason As String = CType(e.Item.FindControl("txtEditReason"), TextBox).Text<br />
<br />
        Dim sql As String<br />
<br />
        Try<br />
            sql = "UPDATE tblVolDeclinedMissedCanceledAssignments " & _<br />
                  "SET Date=@Date, Assignment=@Assignment, SchoolVenue=@SchoolVenue, Programme=@Programme, Subject=@Subject, City=@City, StateProvince=@StateProvince, Reason=@Reason " & _<br />
                  "WHERE VolunteerId=" & Me.VolunteerId & " AND Id=" & e.CommandArgument<br />
<br />
            Dim cmd As New SqlCommand(sql, cn)<br />
            cmd.Parameters.AddWithValue("@Date", strDate)<br />
            cmd.Parameters.AddWithValue("@Assignment", strAssignment)<br />
            cmd.Parameters.AddWithValue("@SchoolVenue", strSchoolVenue)<br />
            cmd.Parameters.AddWithValue("@Programme", strProgramme)<br />
            cmd.Parameters.AddWithValue("@Subject", strSubject)<br />
            cmd.Parameters.AddWithValue("@City", strCity)<br />
            cmd.Parameters.AddWithValue("@StateProvince", strStateProvince)<br />
            cmd.Parameters.AddWithValue("@Reason", strReason)<br />
            cn.Open()<br />
<br />
            cmd.ExecuteNonQuery()<br />
<br />
        Catch ex As Exception<br />
            Throw New Exception<br />
        Finally<br />
            cn.Close()<br />
        End Try<br />
<br />
        DataList.EditItemIndex = -1<br />
        LoadDataMSCAData()<br />
<br />
    End Sub<br />


I have allreay read a bunch of forums and articals and can't figure out what I missing. If anyone here could tell me what I'm missing that would be great.

Thanks,

-Adam N. Thompson

GeneralPerformance of ASP.NET application Pin
hashok1-Apr-08 8:08
hashok1-Apr-08 8:08 
GeneralRe: Performance of ASP.NET application Pin
led mike1-Apr-08 10:02
led mike1-Apr-08 10:02 
QuestionSome TextBox when run takes a yellow back color .. Why? Pin
kindman_nb1-Apr-08 7:37
kindman_nb1-Apr-08 7:37 
AnswerRe: Some TextBox when run takes a yellow back color .. Why? Pin
pmarfleet1-Apr-08 8:09
pmarfleet1-Apr-08 8:09 
GeneralRe: Some TextBox when run takes a yellow back color .. Why? Pin
kindman_nb1-Apr-08 19:40
kindman_nb1-Apr-08 19:40 
GeneralJava Script Prompt Pin
Abhijit Jana1-Apr-08 6:32
professionalAbhijit Jana1-Apr-08 6:32 
GeneralRe: Java Script Prompt Pin
pmarfleet1-Apr-08 8:17
pmarfleet1-Apr-08 8:17 
GeneralSync Outlook Calendar with Web Application Pin
guardianhm1-Apr-08 6:12
guardianhm1-Apr-08 6:12 
GeneralRe: Sync Outlook Calendar with Web Application Pin
Abhijit Jana1-Apr-08 6:27
professionalAbhijit Jana1-Apr-08 6:27 
GeneralRe: Sync Outlook Calendar with Web Application Pin
guardianhm1-Apr-08 22:05
guardianhm1-Apr-08 22:05 
GeneralProblem with hyperlink Pin
eyeseetee1-Apr-08 5:16
eyeseetee1-Apr-08 5:16 
GeneralRe: Problem with hyperlink Pin
led mike1-Apr-08 5:27
led mike1-Apr-08 5:27 
GeneralRe: Problem with hyperlink Pin
eyeseetee1-Apr-08 5:33
eyeseetee1-Apr-08 5:33 
GeneralRe: Problem with hyperlink Pin
led mike1-Apr-08 5:41
led mike1-Apr-08 5:41 
GeneralRe: Problem with hyperlink Pin
eyeseetee1-Apr-08 5:46
eyeseetee1-Apr-08 5:46 
GeneralRe: Problem with hyperlink Pin
led mike1-Apr-08 6:13
led mike1-Apr-08 6:13 
GeneralRe: Problem with hyperlink Pin
J4amieC1-Apr-08 6:13
J4amieC1-Apr-08 6:13 

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.