views:

29

answers:

2

Markup

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False">
   <Columns>
      <asp:BoundField DataField="insured_first_name" HeaderText="First Name" />
      <asp:BoundField DataField="insured_first_name" HeaderText="Middle Name" />
      <asp:BoundField DataField="insured_last_name" HeaderText="Last Name" />
   </Columns>
</asp:GridView>

Code

GridView1.DataSource = _dataSet
DataBind()

Whenever my GridView populates, if there is no value to return from my _dataSet for a field, my GridView stops populating after that. Shouldn't it skip that and continue populating the rest of the grid? It seems the GridView won't accept an empty/null value. Any work-around for this?

+4  A: 

The null is causing a dataerror event to be triggered which your gridview is not recovering from.

You should sterilize null values prior to adding them as a datasource for your gridview.

Check out: http://msdn.microsoft.com/en-us/library/ms366709.aspx for more information.

Michael Eakins
Great, thank you. My grid is populating completely now, but do you know how to get the 'NullDisplayText' I entered to actually show up in my grid? I put "---" for the nullDisplayText, buy my grid just leaves an empty cell. Not really a problem for me but it would be nice if I could get my "---" text to show up. Thanks again.
+2  A: 

The stored procedure is not returning the rows with NULL values. Typically, the problem lies within the SQL Statement of the Stored Procedure; usually the catalyst is a join problem. Test the Stored Procedure in SQL Server Management Studio to determine if the results are what you expect.

GridView's have no problem displaying cells with NULL values. They will be just empty cells. It is also a good practice to assign defaults instead of using NULL values within your SQL database. NULL values cause problems with logic such as bit fields. If one is checking for 1 or 0, for instance, he or she may not even consider NULL until after the production phase and that scenario has slipped by development and testing..

Hope that helps

Breakskater