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.