title: asp.net checkboxlist bind to multiple columns
body: <p>I have a scenario where I want to bind three different columns to the checkboxlist</p>
  
  <pre><code>Datatable dt = GetDataTable("Select col1,col2,col3 from mytable where id={0}");
  </code></pre>
  
  <p>I am able to get the data via my GetDataTable method , and now I want to bind this data to the checkboxlist and the col1,col2 and col3 are boolean values, </p>
  
  <p>Checkboxlist should be able to bind to those bool values. And also I need to know how to get the selected values in order to update my database.</p>
  
  <p>Update : - </p>
  
  <p>Sample data would be like - personal, business, other</p>
  
  <p>DataTable would be - </p>
  
  <pre><code>Personal Business Other 
   True     False    True
  </code></pre>
  
  <p>I have to represent this in the checkboxlist </p>
  
  <p>I am doing something like this and I am sure there is a better/easy way of doing this</p>
  
  <pre><code>foreach (ListItem item in chkBox.Items)
                              {
                                  item.Selected = ShouldItemBeSelected(item.Text);
                              }
  
        private bool ShouldItemBeSelected(string value)
          {   string id = getId();
              string query = string.Format("select {0} FROM [dbo].[mytable] where ID='{1}'",value, id);
              bool result = false;
              DataTable dt = GetDataTable(query);
              foreach (DataRow row in dt.Rows)
              {
                  result = Convert.ToBoolean(row[value]);
              }
  
              return result;
          }
  </code></pre>
  
  <p>Thanks!</p>