Thanks Lee Dumond for your generous reply, but no luck pal! I put the emptyTemplate tags in my gridview but still am getting the error "Object reference not set to an instance of an object", NULL referenceException was unhandeled by user code"
When I debug my code i found out that when my sql returns no records the grid can not even find the controls but when there are records returned thats when the grid can find the controls. I tried to put the default values when no records are found using the ISNULL(filed,0.00) but the grid can not find the controls when no records returned. I really need some help pal!!
Here is the code for my gridview:
Code:
<asp:GridView ID="GridViewloans" runat="server" AutoGenerateColumns="False"
BackColor="White" BorderColor="#CC9966" BorderStyle="None" BorderWidth="1px"
CellPadding="4" Width="607px" ShowFooter="True">
<Columns>
<asp:BoundField DataField="Loan_description" HeaderText="Loan Type" />
<asp:BoundField DataField="Date_taken" HeaderText="Date Taken"
DataFormatString="{0:d}" />
<asp:TemplateField HeaderText="Amount Taken">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("amount_taken") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:Label ID="lblTotAmountTaken" runat="server" Font-Bold="True"
Font-Names="verdana" ForeColor="Black"></asp:Label>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server"
Text='<%# Bind("amount_taken", "{0:n2}") %>'></asp:Label>
</ItemTemplate>
<FooterStyle HorizontalAlign="Right" />
<ItemStyle HorizontalAlign="Right" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Monthly Installment">
<EditItemTemplate>
<asp:TextBox ID="TextBox2" runat="server"
Text='<%# Bind("Loan_Installment") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:Label ID="lblTotMonthlyInstallment" runat="server" Font-Bold="True"
Font-Names="verdana" ForeColor="Black"></asp:Label>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server"
Text='<%# Bind("Loan_Installment", "{0:n2}") %>'></asp:Label>
</ItemTemplate>
<FooterStyle HorizontalAlign="Right" />
<ItemStyle HorizontalAlign="Right" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Loan Balance">
<EditItemTemplate>
<asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("loan_balance") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:Label ID="lblTotLoanBalance" runat="server" Font-Bold="True"
ForeColor="Black" style="text-align: right"></asp:Label>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="Label3" runat="server"
Text='<%# Bind("loan_balance", "{0:n2}") %>'></asp:Label>
</ItemTemplate>
<FooterStyle HorizontalAlign="Right" />
<ItemStyle HorizontalAlign="Right" />
</asp:TemplateField>
</Columns>
<EmptyDataTemplate>
No Pending Loans!!!
</EmptyDataTemplate>
<FooterStyle BackColor="#FFFFCC" ForeColor="#330099" />
<HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="#FFFFCC" />
<PagerStyle BackColor="#FFFFCC" ForeColor="#330099" HorizontalAlign="Center" />
<RowStyle BackColor="White" ForeColor="#330099" />
<SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="#663399" />
</asp:GridView>