This is a migrated thread and some comments may be shown as answers.

GridCheckBoxColumn and LinqtoSQL

2 Answers 97 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Elliott
Top achievements
Rank 2
Elliott asked on 30 Jun 2010, 06:55 PM
the GridCheckBoxColumn and LinqtoSQL don't seem to play well together
a LinqtoSQL data source seems to completely bypass a postback (a good thing, usually) so I can't just go into the ItemDataBinding event and manually set the column
the column appears but doesn't show any data
if I add a DataType an exception is thrown - something about being unable to convert a string to boolean
any assistance is appreciated
I'm working in VS2010, SQL Server 2005, latest and greatest Telerik RAD Ajax controls

the relevant aspx
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="AdminPage.aspx.vb" Inherits="AdminPage" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Admin Page</title>
</head>
<body>
<form id="frmAdmin" runat="server">
    <telerik:RadScriptManager ID="rsManager" runat="server" />
    <table>
    <tr>
    <td>
        <telerik:RadGrid ID="gvVendor" DataSourceID="ldsVendor" runat="server">
        <MasterTableView DataKeyNames="VendorID" AutoGenerateColumns="false" AllowSorting="true" AllowPaging="true" CommandItemDisplay="Top" >
        <Columns>
            <telerik:GridBoundColumn UniqueName="VendorID" DataField="VendorID" HeaderText="VendorID" ReadOnly="true" />
            <telerik:GridBoundColumn UniqueName="VendorName" DataField="VendorName" HeaderText="Vendor Name" />
            <telerik:GridBoundColumn UniqueName="LNSPrefix" DataField="LNSPrefix" HeaderText="LNSPrefix" />
            <telerik:GridBoundColumn UniqueName="KMSPrefix" DataField="KMSPrefix" HeaderText="KMSPrefix" />
            <telerik:GridCheckBoxColumn UniqueName="RepGroupFlag" DataFieldName="RepGroupFlag" HeaderText="Rep Group?" />
            <telerik:GridEditCommandColumn UniqueName="btnEdit" />
            <telerik:GridClientDeleteColumn UniqueName="btnDelete" />
        </Columns>
        </MasterTableView>
        </telerik:RadGrid>
    </td>
    </tr>
    </table>
    <asp:LinqDataSource ID="ldsVendor" TableName="Vendors" ContextTypeName="LtSVandorDataContext" EntityTypeName=""
        Select="new (VendorID,VendorName,LNSPrefix,KMSPrefix,RepGroupFlag)" OrderBy="VendorName"
        EnableDelete="True" EnableInsert="True" EnableUpdate="True" runat="server"></asp:LinqDataSource>
</form>
</body>
</html>

code behind
Imports System.Data
Imports Telerik.Web.UI

Partial Class AdminPage
    Inherits System.Web.UI.Page
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Page.IsPostBack Then
            Exit Sub
        End If
    End Sub

why won't the grid set the checkbox properly?
I get a String was not recognized as a valid Boolean. exception thrown - but the column is tinyint
adding a DataType of System.Int16 does nothing

Marianne




2 Answers, 1 is accepted

Sort by
0
Accepted
Martin
Telerik team
answered on 06 Jul 2010, 08:23 AM
Hello Marianne,

Here is a small quote from our documentation:

"GridCheckBoxColumn displays a check box to represent a boolean value. Bind this column type to a boolean field by setting its DataField property. If this column type is bound to a data value that is not boolean, the grid throws an exception."

Based on that I would suggest that you try binding your GridCheckBoxColumn to a valid boolean field and verify whether the issue still exists.

I hope this helps,
Martin
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Elliott
Top achievements
Rank 2
answered on 06 Jul 2010, 01:18 PM
thanks
I left the SQL alone (returning TINYINT) and on the ItemDataBound event handler isolated both the checkbox and the underlying datagridrow
on update, pass the boolean from the checkbox to the update routine and if yes then 1 else 0

or I could have put a case statement in the stored procedure which builds the grid to return True if 1 or False if 0
Tags
Grid
Asked by
Elliott
Top achievements
Rank 2
Answers by
Martin
Telerik team
Elliott
Top achievements
Rank 2
Share this question
or