conditional in datagrid column

  • Thread starter Thread starter DC Gringo
  • Start date Start date
D

DC Gringo

I have a simple datagrid and need to output the value of "0" (zero) if the
value is null.

<asp:BoundColumn DataField="clnPopulationCensus"
SortExpression="clnPopulationCensus" HeaderText="Population (Census)"
DataFormatString=""></asp:BoundColumn>

Would this go in the DataFormatString column? Or somewhere else?

Here's my adapter:

'SqlDataAdapter1
'
Me.SqlDataAdapter1.SelectCommand = Me.SqlSelectCommand1
Me.SqlDataAdapter1.TableMappings.AddRange(New
System.Data.Common.DataTableMapping() {New
System.Data.Common.DataTableMapping("Table", "sac1SelectSurvey1", New
System.Data.Common.DataColumnMapping() {New
System.Data.Common.DataColumnMapping("clnGUID", "clnGUID"), New
System.Data.Common.DataColumnMapping("clnPriorityCorrectedTC",
"clnPriorityCorrectedTC"), New
System.Data.Common.DataColumnMapping("clnMADoneTC", "clnMADoneTC"), New
System.Data.Common.DataColumnMapping("clnMASchoolTC", "clnMASchoolTC"), New
System.Data.Common.DataColumnMapping("clnMAPosterTC", "clnMAPosterTC"), New
System.Data.Common.DataColumnMapping("clnMARadioTC", "clnMARadioTC"), New
System.Data.Common.DataColumnMapping("clnMAPerformingGroupTC",
"clnMAPerformingGroupTC"), New
System.Data.Common.DataColumnMapping("clnMACommunityCenterTC",
"clnMACommunityCenterTC"), New
System.Data.Common.DataColumnMapping("clnMAReligiousOrganizationTC",
"clnMAReligiousOrganizationTC"), New
System.Data.Common.DataColumnMapping("clnMAOtherTC", "clnMAOtherTC"), New
System.Data.Common.DataColumnMapping("clnMAOther", "clnMAOther"), New
System.Data.Common.DataColumnMapping("clnMAOrganisation",
"clnMAOrganisation")}), New System.Data.Common.DataTableMapping("Table1",
"Table1", New System.Data.Common.DataColumnMapping() {New
System.Data.Common.DataColumnMapping("clnGUID", "clnGUID"), New
System.Data.Common.DataColumnMapping("clnName", "clnName")})})


--
__________________________
Glenn Levine
(e-mail address removed)

Cell: (202) 374-4871
Home: (703) 212-6723

"One never knows, does one?"
 
Hi DC Gringo,

I cannot see if you did use the designer from VS.net and did drag things to
your form, but when you want to put a datatable from a database in a
datagrid you need minimal the folowing

a connection with your database (SqlConnection)
a dataset
a SqlDataAdapter
a Datagrid

The dataset can be bounded using the datasourse to the datagrid.

To see a lot of examples for that try to use this.

http://msdn.microsoft.com/vbasic/vbrkit/default.aspx

And if you have problems installing it

http://msdn.microsoft.com/vbasic/vbrkit/faq/#installvdir

I hope this helps a little bit?

Cor
 
* "DC Gringo said:
I have a simple datagrid and need to output the value of "0" (zero) if the
value is null.

<asp:BoundColumn DataField="clnPopulationCensus"
SortExpression="clnPopulationCensus" HeaderText="Population (Census)"
DataFormatString=""></asp:BoundColumn>

Group for ASP.NET DataGrid:

<
 
Cor,

Yes, of course, all of that is in place and my datagrid is showing. I did
use the VS.NET designer as you described. What I'm looking for help on is
how to alter data values based on conditional processing within this
framework.

In particular, if a data value is null, I want to show a zero or a "none"
value.

_____
Glenn

I'm just looking to deal with the output.
 
Hi DC,

I am not that deep in the datagrid webcontrol that I know if there are easy
posibilities for your last question. But you can ask this also in the

Microsoft.public.dotnet.framework.aspnet.datagridcontrol newsgroup.

However because you did all with the designer I think you are limited and
for this kind of things you mostly have to go deep in the code.

databinding events can maybe do something for you. But for that you have to
go really deep in handmade code.

An alternative is adding extra colomns to your datasource but that needs
good knowledge from datatables.

However better is if you ask your question as simple as you ask did in your
last message in the newsgroup I did tell you above.

But do not forget to tell that you did make everything using the designer,
otherwise you get scripting answers or very deep hand made answers.

Sorry no solution in this answer.

Cor
 
When I try to change the header text after Databind for a column I am getting the following error:
dgTest.Columns(0).HeaderText = "TEST#"

Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index

PS: I am using .Net 2002 with servicepack2
 
Back
Top