grid view error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nehaneha
    New Member
    • Nov 2007
    • 7

    grid view error

    [Code=cpp]
    void GridView1_DataB ound(object sender, EventArgs e)
    {
    DropDownList ddl = (DropDownList)G ridView1.FindCo ntrol("drpmarks ");
    DataTable dt= ClassLibrary1.C lass1.FetchMark s( 21);
    ddl.DataSource = dt;
    ddl.DataTextFie ld = "Marks";
    ddl.DataValueFi eld = "employeeid ";
    ddl.DataBind();

    }
    [/code]
    when i run iam getting error as null reference . can any body tell what is the problem
    Last edited by Frinavale; Nov 16 '07, 02:49 PM. Reason: Added [code] tags
  • kenobewan
    Recognized Expert Specialist
    • Dec 2006
    • 4871

    #2
    Your data table is prob empty, which line is the error?

    Comment

    • mzmishra
      Recognized Expert Contributor
      • Aug 2007
      • 390

      #3
      Does this line returns a DataTable
      ClassLibrary1.C lass1.FetchMark s( 21)

      Comment

      • Frinavale
        Recognized Expert Expert
        • Oct 2006
        • 9749

        #4
        Originally posted by nehaneha
        [Code=cpp]
        void GridView1_DataB ound(object sender, EventArgs e)
        {
        DropDownList ddl = (DropDownList)G ridView1.FindCo ntrol("drpmarks ");
        DataTable dt= ClassLibrary1.C lass1.FetchMark s( 21);
        ddl.DataSource = dt;
        ddl.DataTextFie ld = "Marks";
        ddl.DataValueFi eld = "employeeid ";
        ddl.DataBind();

        }
        [/code]
        when i run iam getting error as null reference . can any body tell what is the problem
        Make sure that your GridView has the dropDownList "drpmarks" and also that your ClassLibrary1.C lass1.FetchMark s returns an object to you that exists (is not null).

        I also suggest changing your code to use a Try/Catch block so that you can set the NULL object to a reference of something when this occurs.

        -Frinny

        Comment

        • nehaneha
          New Member
          • Nov 2007
          • 7

          #5
          Originally posted by kenobewan
          Your data table is prob empty, which line is the error?

          no my datatable is not empty in dt iam getting 5 records but still iam getting an error . can't we bind directly datatable like that

          Comment

          • nehaneha
            New Member
            • Nov 2007
            • 7

            #6
            Originally posted by mzmishra
            Does this line returns a DataTable
            ClassLibrary1.C lass1.FetchMark s( 21)

            yes it is returning 5 records . can't we bind datatable directly

            Comment

            • Shashi Sadasivan
              Recognized Expert Top Contributor
              • Aug 2007
              • 1435

              #7
              Could you please mention which line is the error being reported?

              Comment

              • nehaneha
                New Member
                • Nov 2007
                • 7

                #8
                Originally posted by Shashi Sadasivan
                Could you please mention which line is the error being reported?

                ddl.DataSource = mytable;

                in this line iam getting an error

                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.NullRefe renceException: Object reference not set to an instance of an object.

                Source Error:


                Line 87: }
                Line 88:
                Line 89: ddl.DataSource = mytable;
                Line 90: ddl.DataTextFie ld = "Rank";
                Line 91: ddl.DataValueFi eld = "ProposalID ";

                Comment

                • Shashi Sadasivan
                  Recognized Expert Top Contributor
                  • Aug 2007
                  • 1435

                  #9
                  Hi nehaneha
                  This only means that
                  [CODE=cpp]DataTable dt= ClassLibrary1.C lass1.FetchMark s( 21);[/CODE]
                  is returning null.
                  So maybe its time to revisit that code.
                  I am unaware of what object type ClassLibrary1.C lass1 is
                  If it is fetching values from a database, you should check the SQL statement being genereated and the actual result of it.

                  cheers

                  Comment

                  Working...