Bind dataset to Checkbox column in asp/net gridview
Posted on 2013-12-09
I am binding a asp.net gridview to a dataset in a webform using vb.net. I am able to populate the grid expect the first column in the grid is a checkbox that I have placed in a template field. That value that I want to display in the check box column is a true/false value stored as a bit in the SQL Server database.
I have tried all of the examples found here and either none of the check boxes are checked when they should be and no error is returned.
If have tried the following: (isApproved is the column name in the dataset)
.......Checked='<%# DataBinder.Eval(Container.DataItem, "isApproved") %>'/> ... No errors returned but no check boxes checked either
.......Checked='<%#If(Eval("IsApproved").ToString(), True, False)%>' ... No errors returned but no check boxes checked either
in the GridView1_RowDataBound event I tried.... and got the error "Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index "
...If e.Row.RowType = DataControlRowType.DataRow Then
Dim chk As Boolean = Convert.ToBoolean((Me.GridView1.DataKeys e.Row.RowIndex).Value.ToString()))
'Find Check Box Now
Dim chkBox As CheckBox = DirectCast(e.Row.FindControl("AcctApproved"), CheckBox)
chkBox.Checked = chk
Any help would be greatly appreciated