Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Andrzejek on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Evalualing a bool true/false within an asp:label tag 1

Status
Not open for further replies.

PushCode

Programmer
Dec 17, 2003
573
US
Just looking for someone to confirm that what I have is correct or not.

I have an asp:label field for and expire date that should either display "Never" if the database field ([msDS-UserDontExpirePassword] this is a bit - true/false - field) is True, or otherwise display a date (pwdExpireDate).

My code doesn't throw any errors but I can' fully test it without putting it into production. Can someone tell me if this is correct? Also, there is no code-behind and I can't use code behind for this.

Here's the code:
The label: <asp:Label ID="lbUserPWExpireDate" Text='<%# ((bool)(Eval("[msDS-UserDontExpirePassword]"))==true ? "Never" : Eval("pwdExpireDate", "{0:M/dd/yyyy}")) %>' Runat="Server"/>

The query: <asp:SqlDataSource ID="GetUserExpireDate" runat="server"
ConnectionString="<%$ ConnectionStrings:USER_PREFERENCESConnectionString %>"
SelectCommand="SELECT DATEADD(day, 59, pwdLastSetDateGMT) AS pwdExpireDate, [msDS-UserDontExpirePassword]
FROM LDAP_Users
WHERE mail = @USER_EMAIL_ADDRESS" OnSelecting="GetUserExpireDate_Selecting">
<SelectParameters>
<asp:SessionParameter Name="USER_EMAIL_ADDRESS" SessionField="USER_EMAIL_ADDRESS" />
</SelectParameters>
</asp:SqlDataSource>

Thanks for any help!
 
My code doesn't throw any errors but I can' fully test it without putting it into production. Can someone tell me if this is correct? Also, there is no code-behind and I can't use code behind for this.
separate the code from the view. the view should be as thin and "dumb" as possible. the less your code is dependent on the environment (and other components) the easier it will be be to test your code with automated tests.
nunit, mbunit, xunit, mstest are all testing frameworks which shorten the development feedback loop.

that said your current code will fail if the value is null or DbNull.Value. Use Convert instead
Code:
<%# System.Convert.ToBoolean(Eval("msDS-UserDontExpirePassword")) ? "Never" : Eval("pwdExpireDate", "{0:M/dd/yyyy}") %>

Jason Meckley
Programmer

faq855-7190
faq732-7259
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top