I have a listview and am reading data into it using a SQL statement. I don't want to show NULL in the SIZE_ORDERED column, so whenever the value for this filed is NULL I want to display an empty string. So in code behind I am using the ISNULL property for
the field as shown in bold.
str = "select [PE_PERSON_ID], [DATE_POINT_EXPIRED], [SERVICE_PRIZE_ID], [POINT_USED], [CUSTOM_TEXT], [DATE_RECORD_CREATED], [IND_CUSTOM_YEAR_SELECTED],
ISNULL(SIZE_ORDERED,' ') AS SIZE_ORDERED_2, [COLOR_ORDERED], [PLAQUE_PICTURE] FROM [ADM_PERSON_PRIZE_ORDER] WHERE ([DATE_RECORD_CREATED] BETWEEN '" + startdatetime + "' AND '" + enddatetime + "') ORDER BY [DATE_RECORD_CREATED] ASC";
Then I updated my listview to read value from this new column name.
brightmolly
Member
1 Points
9 Posts
Display an empty string instead of NULL in Listview column using ASP.NET c#
Jul 18, 2012 01:49 PM|LINK
I have a listview and am reading data into it using a SQL statement. I don't want to show NULL in the SIZE_ORDERED column, so whenever the value for this filed is NULL I want to display an empty string. So in code behind I am using the ISNULL property for the field as shown in bold.
str = "select [PE_PERSON_ID], [DATE_POINT_EXPIRED], [SERVICE_PRIZE_ID], [POINT_USED], [CUSTOM_TEXT], [DATE_RECORD_CREATED], [IND_CUSTOM_YEAR_SELECTED], ISNULL(SIZE_ORDERED,' ') AS SIZE_ORDERED_2, [COLOR_ORDERED], [PLAQUE_PICTURE] FROM [ADM_PERSON_PRIZE_ORDER] WHERE ([DATE_RECORD_CREATED] BETWEEN '" + startdatetime + "' AND '" + enddatetime + "') ORDER BY [DATE_RECORD_CREATED] ASC";
Then I updated my listview to read value from this new column name.
<asp:ListView ID="ListView1" runat="server" Visible="False" >
<AlternatingItemTemplate>
<tr style="background-color:white; color:black; " >
<td>
<asp:Label ID="PE_PERSON_IDLabel" runat="server"
Text='<%# Eval("PE_PERSON_ID") %>' />
</td>
<td>
<asp:Label ID="DATE_POINT_EXPIREDLabel" runat="server"
Text='<%# Eval("DATE_POINT_EXPIRED") %>' />
</td>
<td>
<asp:Label ID="SERVICE_PRIZE_IDLabel" runat="server"
Text='<%# Eval("SERVICE_PRIZE_ID") %>' />
</td>
<td>
<asp:Label ID="POINT_USEDLabel" runat="server"
Text='<%# Eval("POINT_USED") %>' />
</td>
<td>
<asp:Label ID="CUSTOM_TEXTLabel" runat="server"
Text='<%# Eval("CUSTOM_TEXT") %>' />
</td>
<td>
<asp:Label ID="DATE_RECORD_CREATEDLabel" runat="server"
Text='<%# Eval("DATE_RECORD_CREATED") %>' />
</td>
<td>
<asp:Label ID="IND_CUSTOM_YEAR_SELECTEDLabel" runat="server"
Text='<%# Eval("IND_CUSTOM_YEAR_SELECTED") %>' />
</td>
<td>
<asp:Label ID="SIZE_ORDEREDLabel" runat="server"
Text='<%# Eval("SIZE_ORDERED_2") %>' />
</td>
<td>
<asp:Label ID="COLOR_ORDEREDLabel" runat="server"
Text='<%# Eval("COLOR_ORDERED") %>' />
</td>
<td>
<asp:Label ID="PLAQUE_PICTURELabel" runat="server"
Text='<%# Eval("PLAQUE_PICTURE") %>' />
</td>
</tr>
</AlternatingItemTemplate>
<EmptyDataTemplate>
<table runat="server"
style="background-color: #FFFFFF;border-collapse: collapse;border-color: #999999;border-style:none;border-width:1px;">
<tr>
<td>
No records were found within that date range. Please try again!</td>
</tr>
</table>
</EmptyDataTemplate>
<ItemTemplate>
<tr style="background-color:#DCDCDC;color: #000000;">
<td>
<asp:Label ID="PE_PERSON_IDLabel" runat="server"
Text='<%# Eval("PE_PERSON_ID") %>' />
</td>
<td>
<asp:Label ID="DATE_POINT_EXPIREDLabel" runat="server"
Text='<%# Eval("DATE_POINT_EXPIRED") %>' />
</td>
<td>
<asp:Label ID="SERVICE_PRIZE_IDLabel" runat="server"
Text='<%# Eval("SERVICE_PRIZE_ID") %>' />
</td>
<td>
<asp:Label ID="POINT_USEDLabel" runat="server"
Text='<%# Eval("POINT_USED") %>' />
</td>
<td>
<asp:Label ID="CUSTOM_TEXTLabel" runat="server"
Text='<%# Eval("CUSTOM_TEXT") %>' />
</td>
<td>
<asp:Label ID="DATE_RECORD_CREATEDLabel" runat="server"
Text='<%# Eval("DATE_RECORD_CREATED") %>' />
</td>
<td>
<asp:Label ID="IND_CUSTOM_YEAR_SELECTEDLabel" runat="server"
Text='<%# Eval("IND_CUSTOM_YEAR_SELECTED") %>' />
</td>
<td>
<asp:Label ID="SIZE_ORDEREDLabel" runat="server"
Text='<%# Eval("SIZE_ORDERED_2") %>' />
</td>
<td>
<asp:Label ID="COLOR_ORDEREDLabel" runat="server"
Text='<%# Eval("COLOR_ORDERED") %>' />
</td>
<td>
<asp:Label ID="PLAQUE_PICTURELabel" runat="server"
Text='<%# Eval("PLAQUE_PICTURE") %>' />
</td>
</tr>
</ItemTemplate>
<LayoutTemplate>
<table runat="server">
<tr runat="server">
<td runat="server">
<table ID="itemPlaceholderContainer" runat="server" border="1"
style="background-color: #FFFFFF;border-collapse: collapse;border-color: #999999;border-style:none;border-width:1px;font-family: Verdana, Arial, Helvetica, sans-serif;">
<tr runat="server" style="background-color:#DCDCDC;color: #000000;">
<th runat="server">
PERSON_ID</th>
<th runat="server">
POINT_EXPIRY</th>
<th runat="server">
PRIZE_ID</th>
<th runat="server">
POINT_USED</th>
<th runat="server">
CUST_TEXT</th>
<th runat="server">
REC_CREATED</th>
<th runat="server">
CUST_YEAR</th>
<th runat="server">
SIZE</th>
<th runat="server">
COLOR</th>
<th runat="server">
PLAQUE_PIC</th>
</tr>
<tr ID="itemPlaceholder" runat="server">
</tr>
</table>
</td>
</tr>
<tr runat="server">
<td runat="server"
style="text-align: center;background-color: #CCCCCC;font-family: Verdana, Arial, Helvetica, sans-serif;color: #000000;">
<asp:DataPager ID="DataPager1" runat="server" PageSize="50">
<Fields>
<asp:NextPreviousPagerField ButtonType="Button" ShowFirstPageButton="True"
ShowLastPageButton="True" />
</Fields>
</asp:DataPager>
</td>
</tr>
</table>
</LayoutTemplate>
</asp:ListView>
But this still shows the NULL in SIZE_ORDERED column in listview. What am I missing? Please help.
Mudasir.Khan
All-Star
15346 Points
3142 Posts
Re: Display an empty string instead of NULL in Listview column using ASP.NET c#
Jul 18, 2012 02:35 PM|LINK
try using
COALESCE(SIZE_ORDERED,'') as SIZE_ORDERED_2
brightmolly
Member
1 Points
9 Posts
Re: Display an empty string instead of NULL in Listview column using ASP.NET c#
Jul 18, 2012 03:55 PM|LINK
Thanks for the quick reply Mudasir.
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Display an empty string instead of NULL in Listview column using ASP.NET c#
Jul 20, 2012 01:27 AM|LINK
Any other feedback?Congratulation!