Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 899181
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T15:10:32+00:00 2026-05-15T15:10:32+00:00

What exactly is the e.Row.DataItem return.. MSDN says.. returns An Object that represents the

  • 0

What exactly is the e.Row.DataItem return.. MSDN says.. returns An Object that represents the underlying data object to which the GridViewRow object is bound.

Here is my DataGrid…

    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="ObjectDataSource1" OnRowDataBound="GridView1_RowDataBound">
        <Columns>
            <asp:BoundField DataField="PracticeCode" HeaderText="PracticeCode" SortExpression="PracticeCode" />
            <asp:BoundField DataField="AccountNo" HeaderText="AccountNo" SortExpression="AccountNo" />
            <asp:BoundField DataField="PatientName" HeaderText="PatientName" SortExpression="PatientName" />
            <asp:TemplateField HeaderText="Status">
                <ItemTemplate>
                    <asp:Label ID="LblStatus" runat="server"></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
    </asp:GridView>

And I bind it with my Business Object List < Patient >.. In the row DataBound event, I try this…

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        Patient p1 = (Patient)e.Row.DataItem;
        Label lbl = e.Row.FindControl("LblStatus") as Label;

        if (p1 == null)
        {
            throw new Exception("P1 is null");
        }

        if (p1.OpenItems.Count > 0)
        {
            lbl.Text = "Has open Items";
        }
        else
        {
            lbl.Text = "";
        }
    }

I get the exception P1 is null… Why so… What am I missing..

Note : There could be other ways to accomplish this, but I’m looking especially why my p1 is null… and is there any way to get the Patient Object back from GridView after binding.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T15:10:33+00:00Added an answer on May 15, 2026 at 3:10 pm

    RowDataBound is called for the header and footer also, you need to make sure your currently in an actual DataRow before calling e.Row.DataItem:

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {                
           if(e.Row.RowType != DataControlRowType.DataRow)
              return;
    
           Patient p1 = (Patient)e.Row.DataItem;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given a binary matrix in which every row and column contains exactly only one
A query of mine is meant to return exactly one row (as it is
I have an Update query that recalculates -every- column value in exactly one row,
Exactly as the title says. I've created an @NodeEntity annotated POJO and in it
Exactly what the title says...........any thoughts on other good options for relational database implementation
Exactly when are an Activity 's fields that are annotated with @InjectView or @InjectResource
What exactly does SignedCookieJar do? And what is the difference from that and using
I have a data set that looks like the following. EMPLID PHONE_TYPE PHONE ------
The intention of following (simplified) code fragment is to return one random row .
I have an Incident table with one row that has the value 'out of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.