.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

how to bind a nullable column to a checkbox

Posted By:      Posted Date: October 27, 2010    Points: 0   Category :ASP.Net


I'm trying to bind a nullable column to a checkbox:

<asp:CheckBox ID="SubjectIsSchoolTruantCheckBox" runat="server" Checked='<%# CheckNull(Eval("SubjectIsSchoolTruant")) %>'  />



        protected Boolean CheckNull(Object sItem)
            if (sItem == null)
                return false;

            int i = (int)sItem;

            if (i > 0)
                return true;
                return false;


The value SubjectIsSchoolTruantCheckBox can be null.

I am running into the following error when I try to update:  Failed to set one or more properties on type GRIPS.ActivityMember.   is no

View Complete Post

More Related Resource Links

Unable to Bind a CheckBox to an Oracle column

The code below works great in SQL Server with a BIT column.  How do you get it to work in Oracle?  I've tried number(1), char(1)...etc but nothing works!  Using Eval is no good becuse that breaks the Update. <asp:CheckBox ID="cbxStatus" runat="server" Checked='<%# Bind("status") %>' /> Always get this error: System.InvalidCastException: "Specified cast is not valid".  Anyone know the trick to making this work with Bind? 

wpf datagridview checkbox column selection not working fine.

Hi Experts,in my c#.net windows based wpf application i added  a datagridview.dynamically i added checkboxcolumn to that datagridview DataGridViewCheckBoxColumn cbCol = new DataGridViewCheckBoxColumn(); GridSource.Columns.Add(cbCol); and another column is string. to this column am hardcoding the values DataTable _datatable = new DataTable(); _datatable.Columns.Add("Name", typeof(string)); _datatable.Rows.Add("CSRs"); _datatable.Rows.Add("Customers"); GridSource.DataSource = _datatable; till here fine am getting two columns (checkbox and Name)when i am trying to check those checkboxes problem comming.am trying to get the count of the checked rows for that i used below code int cbcount = 0; foreach (DataGridViewRow _dgRow in GridSource.Rows) { if ((bool)_dgRow.Cells[0].Value) cbcount++; } cbcount will give the checked count.but the problem raising here if i check 2 rows it giving 1if i check 5 rows it giving 4if i check 1 row it giving me 0means am getting n-1 resultwhere i did wrong??

WPF Datagrid with multiple row selection/checkbox column template

Hello, I am using the WPF Toolkit Datagrid with a checkbox defined in a template column/template cell. We are using the checkbox template so that selecting the checkbox will also highlight the row in the datagrid. Here is the template definition: <dg:DataGridTemplateColumn MinWidth="50" Width="Auto" Header="" CanUserReorder="False"> <dg:DataGridTemplateColumn.CellTemplate> <DataTemplate> <CheckBox IsChecked="{Binding Path=IsCheckedm, Mode=TwoWay}" /> </DataTemplate> </dg:DataGridTemplateColumn.CellTemplate> </dg:DataGridTemplateColumn> We are allowing multiple row selection in the datagrid and using MVVM (using MVVM Light). We would like to keep a list in the View Model of selected rows as they are selected/unselected. Any suggestions on how we can leverage MVVM to keep the list of selected/unselected elements current. Many Thanks --Sam

Update nullable column in db to null?

Can anyone reliably get the EDS to save a nullable column to the databse as a "null" when bound to any of the controls such as "FormView"? I have tried using several different UpdateParameters (Session, ControlParamater, Parameter,  etc). I have tried setting "ConvertEmptyStringToNull" to true and leaving the property off entirely. Nothing works. On my "Inserts" it works fine. (I have made sure the column is set to nullable = true in the Entity Designer.....)

Checkbox column not selectable

Hello all, I added a checkbox column and wrote the following code to handle it but checkboxes are not selectable. Any ideas? Private Sub chkBoxAll_Approve(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkButton.Click Dim ctr As New DataGridViewRow Try For Each ctr In dgvRequests.SelectedRows If chkBoxColumn.Selected = True Then Exit For ElseIf dgvRequests.CurrentRow.Cells("requestType").Value = "OOORequest" Then Call updateOutOfOffice(LeaveStatus.Approved) Else Call updateRequest(LeaveStatus.Approved) End If Next Catch ex As System.Exception MessageBox.Show(ex.Message) End Try End Sub  

Finding underlying Eval or Bind column name from TemplateField

I need to be able to get the underlying column name from each TemplateField in my GridView. So I have something like:<asp:TemplateField HeaderText="Current Market Event" SortExpression="current_market_event"> <ItemTemplate> <asp:Label ID="Label2" runat="server" Text='<%# Eval("current_market_event") %>'></asp:Label> </ItemTemplate> </asp:TemplateField> I see how to do this with a BoundField quiet easily: BoundField.DataField. Is there any way to do this for a TemplateField?

Bind combox, ListBox to SQL database column


Hi everyone

  I am having problem where I want to bind a column of the database to the Combobox so that Item of the combobox are present in the database

for example I have a table named Animals which is in the following format

ID   Animal

1    Dog

2    Cat

3    Horse

4   Goat


So the Item of the Combobox are Dog, Cat, Horse and Goat.  I had tried to bind the database to ObservableCollection First and then bind that ObservableCollection to the combobox.

   public class NameList : List<PersonName>
	private LikesLINQDataContext newlikes = new LikesLINQDataContext();

	List<string> depart = new List<string>();

	 public NameList(): base()
		foreach (var lol in newlikes.Likes)

		foreach (stri

rendering a CheckBox web control from Oracle NVARCHAR2 (1) data column


I have a data column in Oracle as NULLABLE NVARCHAR2 (1) which accepts Y for True or N for False and nulls. 

When I have Dynamic Data to render this column, it renders it as a TextBox web control.

Is there a way to make Dynamic Data to render it as a CheckBox web control?


How to set a wpf combobox displaymemberitem to a column in 1 table and bind text displayed to a colu


I have a combobox that has a datacontext set to a 'Customer Type' that is a customer CRUD window in WPF that itself has a datacontext of 'Customer' - when i scroll through my customer table entries that have been populated into a listbox, all of the corresponding textboxes on my CRUD window update to reflect the values stored in the Customer table except the combobox.  If I change the datacontext of the combobox to be 'Customer' the text updates correctly when scrolling through but the dropdown contents are now duplicated to match the number of records.  So my problem is this;

How can I display the itemssource as the 'Customer Type.Customer_Type' datacontext, but display the Text as 'Customer.Customer_Type'?

The closest i could compare it to would be a winforms example of setting the combo's DataSource to 'Customer_Type' on the combo with a displaymember of 'Customer_Type' and then making the DataBindings 'Text' property of the combo to be 'Customer.Customer_Type' so it displays the value stored in customer but as soon as you drop it down it shows non-repeated values that are contained in customer_type.customer_type.

Right now in wpf if the datacontext is customer, the combo displays customer_type as follows:






How to Use checkbox column in SPGridView programatically





I am developing a webpart which displays a SPGridView. I need to have a checkbox in one column in each row of SPGridView. Can anybody know how to do it programatically.



Adding checkbox column to data


I need to add a checkbox column to my data and do it programmatically.  I've seen a lot of other posts that address this, but can't get it to work in VB.

        Dim all3 = From p In all2
                 Let tempCost = db.maximum((p.PosVal - DollarBase) * slope + 1, 1)
                 Let Cost = String.Format("{0:$.}", Convert.ToDouble(tempCost))
                 Select p.Player, p.Team, Cost

        GridView1.DataSource = all3

        'Need to add checkbox code here


Bind gridview column to nested object



not really sure how to phrase this question.

If I have a list of contacts List<Contact> and a Contact object has an Office object property, I want to display a grid with columns

Contact Id, First Name, Last Name, Office Name

Where the sources of the above columns are respectively:

Contact.ContactId, Contact.FirstName, Contact.LastName, Contact.Office.OfficeName

I'm fine with binding the first 3, but was wondering whether I can bind the OfficeName using either Bind or Eval or whether I need to hook into the events and set the value there.






AJAX GridView Checkbox Select All in ASP.Net

In the previous article GridView Select Multiple Rows you learnt the multiple row selection in GridView control. Here you will get the C# code sample to select all the gridview rows using single checkbox server control. You can highlight the selected rows with different color and Font state Bold. If you want to use the selection values on different ASP.Net

jQuery: Highlight Gridview Rows with Checkbox

Im learning and experimenting with jQuery and ASP.NET. Below is a simple solution I created to highlight rows in a gridview by clicking on a checkbox next to the row.

Gridview setup:

jQuery: Highlight Gridview Rows with Checkbox

Im learning and experimenting with jQuery and ASP.NET. Below is a simple solution I created to highlight rows in a gridview by clicking on a checkbox next to the row.

Tooltip for GridView Column Headers (ASP.Net)

I just wanted to add auto tooltips for my GridView headers. There are couple of ways but I don't want to use javascript and wanted to use simple 'title' attribute. It took couple of hours to get the working code supporting sortable columns. I thought it will be very useful for others. Here's the code and logic behind it.

Multiple Column Dropdownlist for the ASP.NET DataGrid

Based on my previous control "Multiple Column DropDownList for ASP.NET", I received many emails asking for the same control to be used in the DataGrid for web applications. Here we go.. This control can be used as the regular MS DropDownList in the DataGrid and also as a regular dropdownlist. It has all the properties, like DataTextField, DataValueField, DataSource, SelectedIndex etc. The download file contains the samples both in VB.NET and C#. In this sample, I have used the Northwind database of SQL Server.
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend