ASP.NET Binding integer to CheckBox's Checked field

前端 未结 6 1104
Happy的楠姐
Happy的楠姐 2021-01-12 13:11

I have a following ListView item template, in which I am trying to bind integer value to Checked property of CheckBox.

IsUploaded value con

相关标签:
6条回答
  • 2021-01-12 13:25

    How about (btw i am using a stored procedure)

    Aspx page

    <asp:CheckBox ID="social_facebook" runat="server"  Checked='<%# Bind("True") %>' />Facebook
    

    Code behind

    cmd.Parameters.Add("@p_facebook", SqlDbType.Bit).Value = social_facebook.Checked;
    
    0 讨论(0)
  • 2021-01-12 13:25

    Solution:

    Hi, I'm also using Ajax rating inside a GridView and I ran into this problem. After looking through several forums, I tried this and it worked for me. I hope it helps you:

    <%# Convert.ToInt32(Eval("EVALUATION")) %>
    

    returns an integer, since you're using Checked which is an integer.

    0 讨论(0)
  • 2021-01-12 13:26

    If you're willing to change the class, add a property on the class that's a boolean

    public bool IsUploadedBoolean
    {
       get { return IsUploaded != 0; }
       set { IsUploaded = value ? 1 : 0; }
    }
    

    If not, you may have success with a TypeConverter:

    1. Create a custom TypeConverter which will handle 0 and 1 to boolean conversions
    2. Stick the TypeConverterAttribute on the IsUploaded property to direct .NET to your custom typeconverter.
    0 讨论(0)
  • 2021-01-12 13:26

    Kind of a cheesy work around would be to use a drop down list with list items to give the same effect:

    <asp:DropDownList ID="ddlBool" runat="server" SelectedValue= '<%# Bind("IsUploaded") %>'>
        <asp:ListItem Text="True" Value="1" />
        <asp:ListItem Text="False" Value="0" />
    </asp:DropDownList>
    
    0 讨论(0)
  • 2021-01-12 13:45

    How about adding a property to your class which does the conversion?

    public bool IsUploadedBool
    {
      get { return IsUploaded == 1; }
    }
    

    and then bind to this IsUploadedBool property instead of directly to the underlying INT.

    Marc

    0 讨论(0)
  • 2021-01-12 13:47

    For more information visit: http://dhondiyals.wordpress.com/2010/05/03/binding-checkbox-with-integer-value-in-gridviewtrick/

    0 讨论(0)
提交回复
热议问题