Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7556979
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T12:00:24+00:00 2026-05-30T12:00:24+00:00

I need a two way databinding between a checkbox and a char field in

  • 0

I need a two way databinding between a checkbox and a char field in the db that can contains Y or N.

The checkbox is within a FormView. Whenever the form is submitted, the bool state of the checkbox is translated into the corresponding Y or N field in the datasource and then committed to the database. I’m using LINQ to SQL Designer to generate the datasource code. Here’s what I had in mind using partials.

<asp:FormView ... datasource="DataSource1" EnableModelValidation="True" DefaultMode ="Edit">
    <EditItemTemplate>
        ...
        <asp:checkbox ... checked='<%# Bind("Enabled") %>'>
        ...
    </EditItemTemplate>
</asp:FormView>

<asp:LinqDataSource ID="DataSource1" runat="server" 
    ContextTypeName="WebPages.WebPagesDataContext" EnableDelete="True" 
    EnableInsert="True" EnableUpdate="True" TableName="Car">
</asp:LinqDataSource>

Then I can add my own Enabled property to the generated datasource using a partial. The partial class is in App_Code and in the same namespace as the linq datasource.

partial class Car 
{
    public bool Enabled
    {
        get { return DbEnabled == 'Y' }
        set { DbEnabled = value ? 'Y' : 'N' }
    }
}

I believe this is the correct way to do it. Currently the checkbox does reflect the state of the database field. However toggling the checkbox and submitting the form doesn’t result in a change in the DbEnabled field in the database.

How is this done?

Edit: The only thing missing to make this work was to make the property DbEnabled set to Private in the Linq to SQL designer.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T12:00:25+00:00Added an answer on May 30, 2026 at 12:00 pm

    You may create private column property and expose it via public property.

    Here is an Emp entity,

    [Table(Name="Emp")]
    public class Emp
    {
        [Column(Name = "No", IsPrimaryKey = true)]
        public int Id { get; set; }
    
        [Column(Name="Name")]
        public string Name { get; set; }
    
        [Column(Name = "Status")]
        private char Status { get; set; }
    
        public bool BoolStatus
        {
            get { return Status == 'Y' ? true : false; }
            set
            {
                if (value)
                    Status = 'Y';
                else
                    Status = 'N';
            }
        }
       public override string ToString()
        {
          return string.Format("{0} {1} {2}", Id, Name, BoolStatus);
         }
    }
    

    And create the context,

     string cnstr = @"connection_string";
     DataContext dx = new DataContext(cnstr);
    
     Table<Emp> emps=dx.GetTable<Emp>();
    
     Emp a = new Emp() { Id=101, Name="Foo", BoolStatus=true  };
     emps.InsertOnSubmit(a);
     dx.SubmitChanges();
    
     foreach(Emp emp in emps)
     {
       Console.WriteLine(emp);
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need a BindingList in my UI to provide two-way databinding between my collection
I need to have two way communication between threads in Tcl and all I
I have a form that has a group of 3 text_fields. I need two
I need a way for a single variable to represent two kinds of objects
I need UNION two tables with creating new field, where 1 for first table,
I need to bind two-way a property of a user control to a property
I have some code where I need two separate required field validators for one
I have an IIS7 hosted service that I need to expose to two different
I have a SL DataGrid that has two columns. I need to be able
I'm in need of a two-way encryption solution for Ruby, such as Blowfish, Rijndael

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.