Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
So I have a database table called [PortfolioPerformance]
Portfolio, int, not null
AnnualReturn, decimal(18,2), not null
Closed, bit, not null
and a SqlDataSource
<asp:SqlDataSource ID="PerformanceDataSource" runat="server"
SelectCommand="SELECT [Portfolio], [AnnualReturn], [Closed] FROM [PortfolioPerformance]"/>
and a ListView
<asp:ListView ID="PerformanceListView" runat="server" DataSourceID="PerformanceDataSource">
...
<ItemTemplate>
  <tr>
    <td>
      <asp:CheckBox ID="ClosedCheckBox" runat="server" Checked='<%# Eval("Closed") %>' Enabled="false" />
    </td>
  </tr>
</ItemTemplate>
And at runtime I get a HttpException "DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'Closed'". If I changed the CheckBox to Checked='false', everything is fine, except the display is wrong.
 
I used a ListView so that users could edit the entry, and editing works fine (that is, the SqlDataSource has no problems with the insert, update, or delete statements, and using Bind("Closed") in the ListView templates doesn't throw exceptions). I've run the select statement in SQL Management Studio and it returns the correct results. Can anyone help?
Posted 19-Jun-12 11:32am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

You need to conver the bit to boolean please refer the following links and convert the value to boolean and then assign the value to checked property..
 

http://stackoverflow.com/questions/1561382/asp-net-binding-integer-to-checkboxs-checked-field[^]
 
http://forums.asp.net/t/917702.aspx/1[^]
 

http://stackoverflow.com/questions/2767352/c-sharp-convert-bit-to-boolean[^]
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

By Using Ternary Operator or Case or Condition you can display the result according to your condition.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

A Case condition doesn't work. When I change the select statement to read
SELECT [Portfolio]
      ,[AnnualReturn]
      ,case
         when [Closed] = 0 then 'false'
         else 'true'
       end as 'Closed'
FROM [PortfolioPerformance]
I still get the exception.
 
What I don't understand is why the view seems to think there isn't a field for Closed - "'System.Data.DataRowView' does not contain a property with the name 'Closed'". I would think a conversion error would produce a different exception and error message.
 
Likewise, a bit conversion still needs to have the field present, so if the DataRowView can't see it, it doesn't matter if the bit is converted or not.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web02 | 2.8.141022.1 | Last Updated 20 Jun 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100