|
-
Apr 26th, 2006, 02:33 PM
#1
[RESOLVED] [2005] Bind Checked Value of Checkbox to DataSource
Hello,
I am hoping you can help cause this is starting to drive me crazy!
I am in the process of converting an ASP.Net Page, coded in VB, to C#. So far everything is going fine, except for the following two lines:
VB Code:
<td align="right"><asp:Label ID="Label2" runat="server" Text=" [Is Approved]" Visible='<%#Eval("IsApproved")%>'/></td>
and
VB Code:
<td colspan="2"><asp:CheckBox ID="IsApproved" Runat="server" checked='<%# Bind("IsApproved")%>' text="Is Approved?" /></td>
When run, there lines produce the following error:
"Specified cast is not valid"
I am returning a boolean in the DataSource, so I am not sure why it is returning an error!
Is there a way to cast to a Boolean in the Bind Statement, or can you think of another way to achieve the desired result, i.e. a tick in the checkkbox when a user is approved and also a visible textbox.
(P.S. I have already posted this question in the C# forum, but no-one seemed to be able to help. SOrry for Cross Posting, can a Mod delete my other post in the C# Forum, Cheers!)
Gary
-
Apr 26th, 2006, 09:33 PM
#2
Junior Member
Re: [2005] Bind Checked Value of Checkbox to DataSource
 Originally Posted by gep13
Code:
Visible='<%#Eval("IsApproved")%>'
Remove the single quote. and if it's still not working.
try to put Page.DataBind() in Page_Load().
Last edited by bunchhel; Apr 26th, 2006 at 09:37 PM.
Help Me Help You.
-
Apr 27th, 2006, 02:07 AM
#3
Re: [2005] Bind Checked Value of Checkbox to DataSource
Hello bunchhel,
I have tried both of the things that you suggested and neither of them worked?!!
Can you think of anything else that I can try?
Cheers
Gary
-
Apr 27th, 2006, 03:03 AM
#4
Junior Member
Re: [2005] Bind Checked Value of Checkbox to DataSource
try this:
Visible=<%#Convert.ToBoolean(DataBinder.Eval(Container.DataItem, "IsApproved"))%>
-
Apr 27th, 2006, 04:06 AM
#5
Re: [2005] Bind Checked Value of Checkbox to DataSource
Thanks for replying again.
I am not at home just now, but I will try that when i get back and let you know how I get on!
Gary
-
Apr 27th, 2006, 12:49 PM
#6
Re: [2005] Bind Checked Value of Checkbox to DataSource
You are the genous, cheers dude!
I have one more expression that is not working properly and I am hoping you can help!
VB Code:
<asp:Panel runat="server" ID="Panel3" Visible='<%# (Eval("CodeCommentCount") > 0) %>'><h5>Code Comments</h5></asp:Panel>
It is failing on the > 0 expression, how would I convert this into a useable format for C#.
Thanks again!!
Gary
-
Apr 27th, 2006, 09:57 PM
#7
Junior Member
Re: [2005] Bind Checked Value of Checkbox to DataSource
Visible=<%#Convert.ToInt32(DataBinder.Eval(Container.DataItem, "CodeCommentCount")) > 0 %>
-
Apr 28th, 2006, 01:29 AM
#8
Re: [2005] Bind Checked Value of Checkbox to DataSource
Thanks again!!!
I posted the same question on the official ASP.Net Forum site and no one has been able to help me!
Cheers!!
Gary
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|