Results 1 to 8 of 8

Thread: [RESOLVED] [2005] Bind Checked Value of Checkbox to DataSource

  1. #1

    Thread Starter
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Resolved [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:
    1. <td align="right"><asp:Label ID="Label2" runat="server" Text=" [Is Approved]" Visible='<%#Eval("IsApproved")%>'/></td>

    and

    VB Code:
    1. <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

  2. #2
    Junior Member
    Join Date
    Mar 2006
    Posts
    25

    Re: [2005] Bind Checked Value of Checkbox to DataSource

    Quote 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.

  3. #3

    Thread Starter
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    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

  4. #4
    Junior Member
    Join Date
    Mar 2006
    Posts
    25

    Re: [2005] Bind Checked Value of Checkbox to DataSource

    try this:
    Visible=<%#Convert.ToBoolean(DataBinder.Eval(Container.DataItem, "IsApproved"))%>
    Help Me Help You.

  5. #5

    Thread Starter
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    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

  6. #6

    Thread Starter
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    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:
    1. <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

  7. #7
    Junior Member
    Join Date
    Mar 2006
    Posts
    25

    Re: [2005] Bind Checked Value of Checkbox to DataSource

    Visible=<%#Convert.ToInt32(DataBinder.Eval(Container.DataItem, "CodeCommentCount")) > 0 %>
    Help Me Help You.

  8. #8

    Thread Starter
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    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
  •  



Click Here to Expand Forum to Full Width