Gridview default cell value???

  • Thread starter Jon S via DotNetMonster.com
  • Start date
J

Jon S via DotNetMonster.com

HI all,

I'm returning a dataset to a gridview control. When the gridview asp.net
control is populated from the returning dataset some of the cells remain
empty. This is expected as some data in the dataset is empty. The cells
that are empty, in the gridview control, I would like to have the value of 0
(zero) inserted. Is there a default cell value property or something similar
for the asp.net gridview control. So if no data is returned to that cell a 0
(zero) is shown.

Thanks in advance.
 
G

Guest

You can program the RowDataBound event to set default values for null entries
http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.rowdatabound(VS.80).aspx

Or you can replace the BoundFields with TemplateFields where the server
controls have conditional databinding expressions to display a default value
if the field value were null, e.g.
<asp:TextBox runat="server"
Text=' said:
</asp:TextBox>
and in the codeBehind:

protected string DefaultVal(string val)
{
if(val == null)
return("0");
else
return(val);

}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top