Contact Sales: +1-888-365-2779
Community & Support
Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET > Grid > asp:Checkbox in FormTemplate. "Specified Cast is Invalid"
RadControls for ASP.NET are no longer supported (see this page for reference). In case you have inquiries about the Telerik ASP.NET AJAX controls, post them in the pertinent ASP.NET AJAX forums.

Not answered asp:Checkbox in FormTemplate. "Specified Cast is Invalid"

Feed from this thread
  • Rowland O'Connor avatar

    Posted on Feb 16, 2006 (permalink)

    Hi,

    Hopefully someone has a solution to this problem. It occurs in ASP.NET 2 when using RadGrid v3.x. The database is MS SQL Server 2000 and the field type in question is "Bit".

    I am using RadGrid EditForm templates. One of the controls is an asp:Checkbox which I am attempting to bind to a SqlDataSource using the <%#Bind("FIELD")%> syntax.

    This creates a "Specified Cast is Invalid" compilation error. All other (text) controls work fine.

    The syntax of the statement that I am using is:

    <asp:CheckBox ID="chkEnabled" runat="server" Checked='<%# Bind("OffersEnabled") %>' TabIndex="1" />

    Does anyone have any knowledge of how to fix this? I have searched Google and it appears that this problem is not uncommon. I can get the control to compile and display the correct value but the problem is then that the value is not saved back to the database.

    The syntax that complies / displays is:
    <asp:CheckBox ID="chkEnabled" runat="server" Checked='<%# (DataBinder.Eval(Container.DataItem,"OffersEnabled").ToString()!="0"?true:false) %>' TabIndex="1" />

    Any clues greatly received:)

    Please note that I would like to do this without resorting to code behind events if possible (RadGrid is complex enough without adding event definitions for every form control object;).

    Regards,

    Rowland O'Connor
    http://www.broadband-help.com

  • Rowland O'Connor avatar

    Posted on Feb 16, 2006 (permalink)

    After a lot of time spent trying to crack this, I have made some progress.

    • Edit works now
    • "Add New Record" still creates "specified cast is invalid"
    I am currently now looking at setting an initial value for the checkbox on Insert.  However, the documentation is less than clear how to go about doing this as it gives an example for a dropdown box as:

    Protected Sub RadGrid1_ItemCommand(ByVal source As Object, ByVal e As Telerik.WebControls.GridCommandEventArgs) Handles RadGrid1.ItemCommand
        If e.CommandName = RadGrid.InitInsertCommandName Then '"Add new" button clicked
          e.Canceled = True
          'Prepare an IDictionary with the predefined values
          Dim newValues As System.Collections.Specialized.ListDictionary = New System.Collections.Specialized.ListDictionary()
          newValues( "TitleOfCourtesy") = "Mrs."
          'Insert the item and rebind
          e.Item.OwnerTableView.InsertItem(newValues)
        End If
    End Sub


    How does this work with a checkbox?

    On a general note, I do find the disjointed and unclear documentation / examples do add a signifficant time overhead on using this control. All I wanted was a checkbox and multiline text box in an edit form and it has taken 2 days so far! (Not exactly "RAD" is it;) )

  • Rowland O'Connor avatar

    Posted on Feb 16, 2006 (permalink)

    3rd and final thread.

    Everything is working now. the key to getting the "Insert" not to fail with "specified Cast is Invalid" is as follows:

    if (e.CommandName == RadGrid.InitInsertCommandName)
            {
                e.Canceled = true;
                System.Collections.Specialized.ListDictionary newValues = new System.Collections.Specialized.ListDictionary();
                newValues["OffersEnabled"] = true;
                //Insert the item and rebind
                e.Item.OwnerTableView.InsertItem(newValues);

               
            }

    The total time to arrive at this point is 2.5 days. I am not sure that the end result of achieving the grid working for simple data edit has been worth the time spent. Better documentation and examples would have helped.

    Having struggled with this, I have some general suggestions for consideration in future releases:-

    • Automatic update edit forms should have an easier way of creating multi line editors. Had this have been possible, it would not have been necessary to use a FormTemplate (the start of my problems with "checkbox" binding)!
    • It should be easier to create initial values for template forms.
    • It should be possible to easily include validation controls in automatic update forms without having to resort to user controls, templates or extensive code behind.
    • Updating data should be simplified. Specifically, the foreach (GridDataItem .... +  e.Item.OwnerTableView.PerformUpdate(item)  in the ItemCommand event should be simplified to one method call (e.g. RadGrid.SelectedItem.PerformUpdate())
    • There are far too many events going on(check out the code behind for many of the online examples). It reminds me of old MS Access forms (yuck!)! Whilst I appreciate the flexibility that exposing all of these events gives, I do believe that many of these events are of no interest to many users of the grid and simply provide information "noise" when trying to figure out what is going on.
    • Having said all of this, Grid v3 is far easier to work with on data updates than previous versions so I suppose we're heading in the right direction:)

    Just my thoughts.

  • Sebastian Sebastian admin's avatar

    Posted on Feb 17, 2006 (permalink)


    Hello Rowland,

    We are glad that you were able to solve the problem yourself. Here is a link to our online help which explains how to set initial values for inserted item fields:

    http://www.telerik.com/help/radgrid/3.0.Net2/?APIForControlling_Net2.html

    In addition, we are happy to inform you that we intend to reorder and enrich the grid documentation for the next version of the control, scheduled for the middle of next month. We believe that you will see many improvements in it and access to the topics will be easier and much more intuitive.

    We will definitely consider the feedback you sent us for grid object model improvements as well. Our aim is to constantly polish our grid control and simplify the tasks our customers should accomplish to configure it to work in line with their requirements. We truly hope that with every version of r.a.d.grid, you will distinguish the improvements/enhancements in every aspect (documentation, QSF examples, object model).

    Thank you once again for sharing your ideas/thoughts with us.

    Have a nice day,
    Stephen
    the telerik team

  • Hien Ho avatar

    Posted on Mar 20, 2006 (permalink)

    Hi all,

    I'm having the same behaviour with Edit. What is the end syntax for the checkbox's Checked property please?

    Thanks...Hien

     

  • Sebastian Sebastian admin's avatar

    Posted on Mar 21, 2006 (permalink)

    Hi Hien,

    To bind the Checked attribute value for your checkbox instance you need to specify a Yes/No column (when using Access data source) or boolean column (using SQL data source) which does not contain null values. Thus you should be able to avoid the specified cast is not valid error.

    Regards,
    Stephen
    the telerik team

  • Posted on Aug 11, 2006 (permalink)

    Rowland,

    I just wanted to thank you for figuring this out and posting here, you saved me hours of work.

  • Thomas Booysen avatar

    Posted on Aug 21, 2006 (permalink)

    A different solution to binding a checkbox in editform to a boolean colomn that can contain nulls:

    <td ><asp:CheckBox

    ID="chkActive"
    runat="server"
    Checked='<%# GenerateBindString(Container.DataItem) %>'
    Text="Active"
    Width="138px" />

    </td>


    and in codebehind:

    protected bool GenerateBindString(object dataItem)
        {
          bool ret = false;

          // if column is null set checkbox.checked = false

          if ((DataBinder.Eval(dataItem, "Status")).ToString() == "")
            ret = false;
          else // set checkbox.checked to boolean value in Status column
            ret = (bool)DataBinder.Eval(dataItem, "Status");
        
          return ret;
        }


  • Eric Downey avatar

    Posted on Oct 31, 2006 (permalink)

    Ok - I'm having exactly the same problem however the above suggestions didn't do the trick for me.  I visited the website help page and saw the dropdown example.  Is the TitleOfCourtesy the ID of the dropdown?  I figured that must be th case so I used my ID cbCampout and assigned False to it as I want the box to be initially unchecked.  When the app did the e.Item.OwnerTableView.InsertItem(newValues) command I got the usual null casting issue.  I also made sure my bound checkbox column was a bit column in the database table and that it did not accept nulls.  That was the way I setup initially.  I did however try setting the default value to 0 but that didn't help.

    I also tried the previous example of writing some code behind to return a true/false value based on the contents of the Container.DataItem.  It works well for display pursposes but I think you loose the Bind that way so when I went to insert it still complained.

    I have to agree with the original poster - these are great controls once you know them.  Until then I have to invent some very elaborate excuses as to why I'm moving slower than with the standard .Net controls.

    Any help would be greatly appreciated as I am completely stuck now....

  • Sebastian Sebastian admin's avatar

    Posted on Nov 1, 2006 (permalink)

    Hi Eric,

    I am sorry to hear that you are having difficulties in configuring the dropdown list instance inside the edit form to display initial value on item insertion. I suggest you review the third paragraph from this topic in the online documentation and especially the part highlighted in yellow:

    http://www.telerik.com/help/radgrid/v4_Net2/?grdErrorMessages.html

    The most important think to have in mind is extracted below:

    When you have template column in the grid make sure that you specify the field to which you bind the control inside the template column as key for the dictionary object (passed to the InsertItem(newValues) method).

    I hope that this information can get you up and going. Thus you can preserve the two-way binding for the combo inside the edit form.

    Best regards,
    Stephen
    the telerik team

  • Eric Downey avatar

    Posted on Nov 1, 2006 (permalink)

    Sorry about the confusion.  I'm trying to do an insert within a grid using a formtemplate.  All of the fields work except the check box control.  Apparently the initial value is a null and, of course, that's not flying.  How can I assign an initial value of false/unchecked to a check box?  Do you have an example of this that you could attach to a reply?  Thanx!

  • Plamen Peshev Plamen Peshev admin's avatar

    Posted on Nov 1, 2006 (permalink)


    Hello Eric,

    Please try to use the following code for the checkbox:

    <asp:CheckBox ID="chkEnabled" runat="server" Checked='<%# (DataBinder.Eval(Container.DataItem,"Status") is DBNull ?false:Eval("Status")) %>' TabIndex="1" /> 
     

    If Status field is null, the checkbox will be unchecked. If this does not help, please send us a small project demonstrating your scenario in a formal support ticket. We will review your code and get back to you with solution for the issue.

    Best regards,
    Plamen
    the telerik team

  • Eric Downey avatar

    Posted on Nov 1, 2006 (permalink)

    I tried what you suggested (I converted it to vb.net)

    <asp:CheckBox ID="cbCampout" Checked='<%# iif(DataBinder.Eval(Container.DataItem,"CAMPOUT") is DBNull.Value,false,Eval("CAMPOUT")) %>' runat="server" />


    and it worked for display purposes when I go into edit/insert mode however when I tried to save a row that I was editing I received an error about trying to store a null.  My guess is that the field is not really bound to the check box so it ends up with a default null value being saved.

  • Plamen Peshev Plamen Peshev admin's avatar

    Posted on Nov 2, 2006 (permalink)


    Hi Eric,

    The following example denonstrates how to update Sql database with bit type

    .apsx
    <%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %> 
     
    <%@ Register Assembly="RadGrid.Net2" Namespace="Telerik.WebControls" TagPrefix="radG" %> 
     
    <!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>Untitled Page</title> 
    </head> 
    <body> 
        <form id="form1" runat="server"
        <div> 
            <radG:RadGrid  
                DataSourceID="SqlDataSource1"  
                ID="RadGrid1"  
                runat="server" OnItemCommand="RadGrid1_ItemCommand"
                <MasterTableView> 
                    <Columns> 
                        <radG:GridEditCommandColumn> 
                        </radG:GridEditCommandColumn> 
                    </Columns> 
                    <EditFormSettings EditFormType="Template"
                        <FormTemplate> 
                            <div> 
                                <asp:Label Text='<%#Eval("Key") %>' ID="Label1"  runat="server"></asp:Label> 
                                <asp:CheckBox ID="chkEnabled" runat="server" Checked='<%# (DataBinder.Eval(Container.DataItem,"Status") is DBNull ?false:Eval("Status")) %>' TabIndex="1" />  
                            </div> 
                            <div> 
                                <asp:Button runat="server" ID="btnUpdate" Text="Update" CommandName="Update" /> 
                            </div> 
                            <div> 
                                <asp:Button runat="server" ID="btnCancel" CommandName="Cancel" Text="Cancel" /> 
                            </div> 
                        </FormTemplate> 
                    </EditFormSettings> 
                </MasterTableView> 
            </radG:RadGrid> 
            <asp:SqlDataSource  
                ID="SqlDataSource1"  
                runat="server"  
                ConnectionString="<%$ ConnectionStrings:dbConnectionString %>" 
                SelectCommand="SELECT * FROM [TestTable]"
            </asp:SqlDataSource> 
        </div> 
        </form> 
    </body> 
    </html> 
     

    .cs
    using System; 
    using System.Data; 
    using System.Configuration; 
    using System.Web; 
    using System.Web.Security; 
    using System.Web.UI; 
    using System.Web.UI.WebControls; 
    using System.Web.UI.WebControls.WebParts; 
    using System.Web.UI.HtmlControls; 
    using Telerik.WebControls; 
     
    public partial class _Default : System.Web.UI.Page  
        protected void Page_Load(object sender, EventArgs e) 
        { 
     
        } 
        protected void RadGrid1_ItemCommand(object source, Telerik.WebControls.GridCommandEventArgs e) 
        { 
            if (e.CommandName == "Update"
            { 
                GridEditFormItem gridEditFormItem = (GridEditFormItem)e.Item; 
                CheckBox checkBox = (CheckBox)gridEditFormItem.FindControl("chkEnabled"); 
                Label label = (Label)gridEditFormItem.FindControl("Label1"); 
                SqlDataSource1.UpdateCommand = "Update TestTable set status='" + checkBox.Checked + "' where [Key]='" + label.Text + "'"
                SqlDataSource1.Update(); 
            } 
        } 
     


    .sql
    USE [db] 
    GO 
    /****** Object:  Table [dbo].[TestTable]    Script Date: 11/02/2006 10:36:07 ******/ 
    SET ANSI_NULLS ON 
    GO 
    SET QUOTED_IDENTIFIER ON 
    GO 
    CREATE TABLE [dbo].[TestTable]( 
        [Key] [numeric](18, 0) IDENTITY(1,1) NOT NULL
        [Desc] [nchar](10) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
        [ApplicationId] [numeric](18, 0) NULL
        [Status] [bitNULL
     CONSTRAINT [PK_TestTable] PRIMARY KEY CLUSTERED  
        [KeyASC 
    )WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFFON [PRIMARY
    ON [PRIMARY


    Let us know whether this helps.

    Ragards,
    Plamen
    the telerik team

  • SR avatar

    Posted on Dec 20, 2006 (permalink)

    It sucks that this is the behaviour in this case.  Not only does the codebehind wire-up for DropDownLists have to be performed, but now also with CheckBoxes as well (To handle the Null).

    Before using the Telerik product(s), I heavily used the Microsoft GridView, FormView, etc.  There too of course the DropDownList wire-up was required, BUT, not with the check boxes!

    Is there any more explaination as to why this occurs with the Telerik RadGrid, but not when using the out-of-box Microsoft stuff.

    I guess i'm a lazy coder, I want to try and minimize code, more code, more maintenance.  I can help but feel these hoops for Check boxes during the insert is 'extra' work that should be unnecessary.

  • Vlad Vlad admin's avatar

    Posted on Dec 20, 2006 (permalink)

    Hello Shawn,

    Feel free to post an example where this works initially with MS GridView and does not work with r.a.d.grid.  We will be glad to review it and see where r.a.d.grid fails. You can post the example in a new support ticket and we will reply here.
     

    Best wishes,
    Vlad
    the telerik team

  • Jeremy Crocker avatar

    Posted on Jan 24, 2007 (permalink)

    Here's a new twist.  I've got several controls in the form template that i need to perform the handling on.  So, I followed the example using the ListDictionary, and this worked wonderfully for my first control.  Step 2, instantiate a new ListDictionary set the proper name to the second instance, and then add it.  This causes problems.  It appears that you can only do this code for 1 control.

    Here is my example
    Control #1 is a RadDatePicker which is bound to "CalendarDate".
    Control #2 is also a RadDatePicker which is bound to "StateHolidayDate".
    Control #3 is a checkbox which is bound to "IsActive".

    So using the code you provided and modifying it to my situation.. this is what i have...  and it works for the control #1, but no other controls... Thoughts?????

    protected void radGrdHolidays_ItemCommand(object source, GridCommandEventArgs e)

    {

    switch (e.CommandName)

    {

            case RadGrid.InitInsertCommandName:
            e.Canceled =
    true;

            //this is for the Calendar Date control
            System.Collections.Specialized.ListDictionary calValues = new System.Collections.Specialized.ListDictionary();

    //assign the field the value desired for default

    calValues["CalendarDate"] = System.DateTime.Today;

    //Insert the item and rebind

    e.Item.OwnerTableView.InsertItem(calValues);

    //this is for the active checkbox control

    System.Collections.Specialized.ListDictionary stateValues =

    new System.Collections.Specialized.ListDictionary();

    //assign the field the value desired for default

    stateValues["StateHolidayDate"] = System.DateTime.Today;

    //Insert the item and rebind

    e.Item.OwnerTableView.InsertItem(stateValues);

    //this is for the active checkbox control

    System.Collections.Specialized.ListDictionary checkBoxValues =

    new System.Collections.Specialized.ListDictionary();

    //assign the field the value desired for default

    checkBoxValues["IsActive"] = System.DateTime.Today;

    //Insert the item and rebind

    e.Item.OwnerTableView.InsertItem(checkBoxValues);

    break;

    default:

    break;

    }

     

    }


  • Sebastian Sebastian admin's avatar

    Posted on Jan 25, 2007 (permalink)

    Hi Jeremy,

    Does setting all dictionary objects keys/values prior to the InsertItem(values) method invocation brings the expected results? Your code should be similar to this one:

    protected void radGrdHolidays_ItemCommand(object source, GridCommandEventArgs e)  
     
    {  
     
    switch (e.CommandName)  
     
    {  
     
            case RadGrid.InitInsertCommandName:  
            e.Canceled = true;  
     
     
            //this is for the Calendar Date control  
            System.Collections.Specialized.ListDictionary calValues = new System.Collections.Specialized.ListDictionary();  
     
     
    //assign the field the value desired for default  
     
    calValues["CalendarDate"] = System.DateTime.Today;  
     
     
    //assign the field the value desired for default  
     
    calValues["StateHolidayDate"] = System.DateTime.Today;  
     
    //assign the field the value desired for default  
     
    calValues["IsActive"] = false;  
     
    //Insert the item and rebind  
     
    e.Item.OwnerTableView.InsertItem(calValues);  
     
    break;  
     
    default:  
     
    break;  
     
    }  
     
       
     
    }  
     

    More details on how to set predefined values for different column editors you can find in this section of the product documentation:

    http://www.telerik.com/help/radgrid/v4_Net2/?grdInsertingValuesInPlaceAndEditForms.html

    You can also find a sample project enclosed to this forum post.

    Best regards,
    Stephen
    the telerik team
    Attached files

  • Jeremy Crocker avatar

    Posted on Jan 25, 2007 (permalink)

    that worked!  thanks!

  • Eric Downey avatar

    Posted on Jun 11, 2007 (permalink)

    Sorry to be the one keeping this thread alive.  I gave up on using the checkbox control in a radgrid's insert mode since it was giving me such a headache.  I decided it is the best model though for another site I'm working on so I'm back to the same issue.  I'm including the code I've created (.aspx and .vb).  It's fairly short and to the point.  I've be very appreciative if anyone at Telerik can look at it and let me know what I'm doing wrong here.  I'm using q3 rad controls.

     

    <%@ Page Language="VB" MasterPageFile="~/masterpages/admin.master" AutoEventWireup="false" CodeFile="AdminLinksPending.aspx.vb" Inherits="admin_AdminLinksPending" title="Untitled Page" Theme="admin" %>

    <%@ Register Assembly="RadGrid.Net2" Namespace="Telerik.WebControls" TagPrefix="radG" %>
    <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <div style="margin: 20px 0px 0px 20px;">
        <br />
        <h2>Administrate Pending Links</h2>
        <br />
        <br />
        <radG:RadGrid AllowAutomaticDeletes="True" AllowAutomaticInserts="True" AllowAutomaticUpdates="True" AutoGenerateColumns="False" ID="rgPendingLinks" runat="server" DataSourceID="adsLinks" EnableAJAX="True" Width="600px"
            HorizontalAlign="NotSet" Skin="Mac" OnItemDeleted="rgPendingLinks_ItemDeleted" OnItemInserted="rgPendingLinks_ItemInserted"  OnItemUpdated="rgPendingLinks_ItemUpdated"  >
            <MasterTableView DataSourceID="adsLinks" DataKeyNames="LINKID" CommandItemDisplay="TopAndBottom" RetrieveNullAsDBNull="true">
                <ExpandCollapseColumn Visible="False" FilterImageUrl="" SortAscImageUrl="" SortDescImageUrl="">
                    <HeaderStyle Width="19px" />
                </ExpandCollapseColumn>
                <RowIndicatorColumn Visible="False">
                    <HeaderStyle Width="20px" />
                </RowIndicatorColumn>
                <EditFormSettings EditFormType="Template">
                    <EditColumn FilterImageUrl="" SortAscImageUrl="" SortDescImageUrl="">
                    </EditColumn>
                    <FormTemplate>
                        <table>
                            <tr>
                                <td>Site name
                                </td>
                                <td><asp:TextBox ID="txtSiteName" Text='<%# Bind ( "SITENAME" ) %>' Width="400px" runat="server" ></asp:TextBox>
                                </td>
                            </tr>
                            <tr>
                                <td>Site address
                                </td>
                                <td><asp:TextBox ID="txtSiteAddress" Text='<%# Bind ( "SITEADDRESS" ) %>' Width="400px" runat="server" ></asp:TextBox>
                                </td>
                            </tr>
                            <tr>
                                <td>Description
                                </td>
                                <td><asp:TextBox TextMode="MultiLine" Rows="5" ID="txtDescription" Text='<%# Bind ( "DESCRIPTION" ) %>' Width="400px" runat="server" ></asp:TextBox>
                                </td>
                            </tr>
                            <tr>
                                <td>Webmaster name
                                </td>
                                <td><asp:TextBox ID="txtWebMasterName" Text='<%# Bind ( "WEBMASTERNAME" ) %>' Width="400px" runat="server" ></asp:TextBox>
                                </td>
                            </tr>
                            <tr>
                                <td>Email
                                </td>
                                <td><asp:TextBox ID="txtEmail" Text='<%# Bind ( "EMAIL" ) %>' Width="400px" runat="server" ></asp:TextBox>
                                </td>
                            </tr>
                            <tr>
                                <td>Password
                                </td>
                                <td><asp:TextBox TextMode="Password" ID="txtPassword" Text='<%# Bind ( "PASSWORD" ) %>' Width="400px" runat="server" ></asp:TextBox>
                                </td>
                            </tr>
                            <tr>
                                <td>Active
                                </td>
                                <td><asp:CheckBox id="cbActive" runat="server" Checked='<%# BIND ("ACTIVE") %>' />
                                </td>
                            </tr>
                            <tr>
                                <td>Created on
                                </td>
                                <td><asp:Label id="lblCreatedOn" runat="server" Text='<%# BIND ( "CREATEDON" ) %>' />
                                </td>
                            </tr>
                            <tr>
                                <td class="DisplayArea"></td>
                                <td align="right" class="EditArea">
                                    <asp:Button ID="btnUpdate" Text='<%# IIf(CType(Container,GridItem).OwnerTableView.IsItemInserted,"Insert","Update") %>'
                                        runat="server" CommandName='<%# IIf(CType(Container,GridItem).OwnerTableView.IsItemInserted ,"PerformInsert","Update") %>'>
                                    </asp:Button>&nbsp;
                                    <asp:Button ID="btnCancel" Text="Cancel" runat="server" CausesValidation="False" CommandName="Cancel"></asp:Button>
                                </td>
                            </tr>   
                        </table>
                    </FormTemplate>
                </EditFormSettings>
                <Columns>
                    <radG:GridEditCommandColumn FilterImageUrl="" SortAscImageUrl="" SortDescImageUrl="" HeaderStyle-Width="100px">
                    </radG:GridEditCommandColumn>
                    <radG:GridButtonColumn CommandName="Delete" Text="Delete" UniqueName="column" HeaderStyle-Width="100px">
                    </radG:GridButtonColumn>
                    <radG:GridBoundColumn DataField="SITENAME" HeaderText="Site Name" SortExpression="SITENAME"
                        UniqueName="SITENAME">
                        <ItemStyle Width="200px" />
                    </radG:GridBoundColumn>
                    <radG:GridBoundColumn DataField="SITEADDRESS" HeaderText="Site Address" SortExpression="SITEADDRESS"
                        UniqueName="SITEADDRESS">
                        <ItemStyle Width="200px" />
                    </radG:GridBoundColumn>
                    <radG:GridBoundColumn DataField="CREATEDON" HeaderText="Created On" SortExpression="CREATEDON" DataFormatString="{0:MM/dd/yy}"
                        UniqueName="CREATEDON">
                        <ItemStyle Width="100px" />
                    </radG:GridBoundColumn>
                </Columns>
            </MasterTableView>
        </radG:RadGrid>
        <asp:Label id="Label1" runat="server"></asp:Label>
        <asp:Label id="Label2" runat="server"></asp:Label>
        <asp:AccessDataSource ID="adsLinks" runat="server" DataFile="~/App_Data/ericdowneydesigns2002.mdb" DeleteCommand="DELETE FROM [tblLinks] WHERE [LinkID] = ?" InsertCommand="INSERT INTO [tblLinks] ([SiteName], [SiteAddress], [Description], [WebmasterName], [Email], [Password], [Active]) VALUES (?, ?, ?, ?, ?, ?, ?)" SelectCommand="SELECT [LinkID], [SiteName], [SiteAddress], [Description], [WebmasterName], [Email], [Password], [CreatedOn], [Active] FROM [tblLinks] WHERE ([Active] = ?) ORDER BY [CreatedOn]" UpdateCommand="UPDATE [tblLinks] SET [SiteName] = ?, [SiteAddress] = ?, [Description] = ?, [WebmasterName] = ?, [Email] = ?, [Password] = ?, [CreatedOn] = ?, [Active] = ? WHERE [LinkID] = ?">
            <DeleteParameters>
                <asp:Parameter Name="LinkID" Type="Int32" />
            </DeleteParameters>
            <UpdateParameters>
                <asp:Parameter Name="SiteName" Type="String" />
                <asp:Parameter Name="SiteAddress" Type="String" />
                <asp:Parameter Name="Description" Type="String" />
                <asp:Parameter Name="WebmasterName" Type="String" />
                <asp:Parameter Name="Email" Type="String" />
                <asp:Parameter Name="Password" Type="String" />
                <asp:Parameter Name="CreatedOn" Type="DateTime" />
                <asp:Parameter DefaultValue="False" Name="Active" Type="Boolean" />
                <asp:Parameter Name="LinkID" Type="Int32" />
            </UpdateParameters>
            <SelectParameters>
                <asp:Parameter DefaultValue="False" Name="Active" Type="Boolean" />
            </SelectParameters>
            <InsertParameters>
                <asp:Parameter Name="SiteName" Type="String" />
                <asp:Parameter Name="SiteAddress" Type="String" />
                <asp:Parameter Name="Description" Type="String" />
                <asp:Parameter Name="WebmasterName" Type="String" />
                <asp:Parameter Name="Email" Type="String" />
                <asp:Parameter Name="Password" Type="String" />
                <asp:Parameter DefaultValue="False" Name="Active" Type="Boolean" />
            </InsertParameters>
        </asp:AccessDataSource>
    </div>
    </asp:Content>

    Imports System.Drawing
    Imports Telerik.WebControls

    Partial Class admin_AdminLinksPending
        Inherits System.Web.UI.Page

        Protected Sub rgPendingLinks_ItemCommand(ByVal source As Object, ByVal e As Telerik.WebControls.GridCommandEventArgs) Handles rgPendingLinks.ItemCommand

            If e.CommandName = RadGrid.InitInsertCommandName Then '"Add new" button clicked
                e.Canceled = True

                'Prepare an IDictionary with the predefined values
                Dim newValues As System.Collections.Specialized.ListDictionary = New System.Collections.Specialized.ListDictionary()

                'set default checked state for checkbox inside the EditItemTemplate
                newValues("ACTIVE") = False

                'Insert the item and rebind
                e.Item.OwnerTableView.InsertItem(newValues)

                Dim editColumn As GridEditCommandColumn = CType(rgPendingLinks.MasterTableView.GetColumn("EditCommandColumn"), GridEditCommandColumn)
                editColumn.Visible = False
            Else
                Dim editColumn As GridEditCommandColumn = CType(rgPendingLinks.MasterTableView.GetColumn("EditCommandColumn"), GridEditCommandColumn)
                If Not editColumn.Visible Then
                    editColumn.Visible = True
                End If

            End If

        End Sub

        Protected Sub rgPendingLinks_ItemUpdated(ByVal source As Object, ByVal e As Telerik.WebControls.GridUpdatedEventArgs) Handles rgPendingLinks.ItemUpdated
            If Not e.Exception Is Nothing Then
                e.KeepInEditMode = True
                e.ExceptionHandled = True
                DisplayMessage(True, "Link " + e.Item.OwnerTableView.DataKeyValues(e.Item.ItemIndex)("LINKID").ToString() + " cannot be updated. Reason: " + e.Exception.Message)
            Else
                DisplayMessage(False, "Link " + e.Item.OwnerTableView.DataKeyValues(e.Item.ItemIndex)("LINKID").ToString() + " updated")
            End If
        End Sub

        Protected Sub rgPendingLinks_ItemDeleted(ByVal source As Object, ByVal e As Telerik.WebControls.GridDeletedEventArgs) Handles rgPendingLinks.ItemDeleted
            If Not e.Exception Is Nothing Then
                e.ExceptionHandled = True
                DisplayMessage(True, "Link " + e.Item.OwnerTableView.DataKeyValues(e.Item.ItemIndex)("LINKID").ToString() + " cannot be deleted. Reason: " + e.Exception.Message)
            Else
                DisplayMessage(False, "Link " + e.Item.OwnerTableView.DataKeyValues(e.Item.ItemIndex)("LINKID").ToString() + " deleted")
            End If
        End Sub

        'Check(DataBinder.Eval(Container.DataItem,"ACTIVE"))
        Protected Function Check(ByVal objStatus As Object) As Boolean
            If (objStatus.ToString().Equals("Yes")) Then
                Return True
            End If

            Return False
        End Function

        Protected Sub rgPendingLinks_ItemInserted(ByVal source As Object, ByVal e As Telerik.WebControls.GridInsertedEventArgs) Handles rgPendingLinks.ItemInserted
            If Not e.Exception Is Nothing Then
                e.ExceptionHandled = True
                e.KeepInInsertMode = False
                DisplayMessage(True, "Link cannot be inserted. Reason: " + e.Exception.Message)
            Else
                DisplayMessage(False, "Link inserted")
            End If
        End Sub

        Private Sub DisplayMessage(ByVal isError As Boolean, ByVal text As String)
            Me.Label1.Font.Bold = True
            Me.Label1.Visible = True
            If (isError) Then
                Me.Label1.ForeColor = Color.Red
            Else
                Me.Label1.ForeColor = Color.Green
            End If
            Me.Label1.Text = text
        End Sub

    End Class



     

  • Yavor Yavor admin's avatar

    Posted on Jun 11, 2007 (permalink)

    Hi Eric,

    Based on the code supplied, I would suggest that you open a formal support ticket, and provide a small working sample, including the database, or a mockup, so that we can test the sample and advise you further.

    Sincerely yours,
    Yavor
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center

  • Posted on Jul 2, 2007 (permalink)

     

    Problems with the Checkbox columns still remain in the latest Q1 2007 version of the controls. However, I've discovered an easy way around binding problems - assuming that your project is making use of the WebUserControl editforms in your grids.

    When browsing through Telerik's demos, I discovered that each control within the editform can be bound to data loaded into the parent grid. The only problem that remained was the Invalid Cast issues with bound Checkboxes.

    The solution is deceptively simple. On the editform WebUserControl, put a hidden TextBox (or Label) and bind it to the boolean datafield that the CheckBox would normally be bound to. The TextBox (or Label) will then contain the words 'True' or 'False' after DataBinding. So, just add the following handler in the Checkbox's PreRender event (will work on other event handlers).

            if (TextBox1.Text.Length > 0)  
                CheckBox1.Checked = Convert.ToBoolean(TextBox1.Text);  
     


    Here's one of the forms I created using this workaround:

    LINKS.ASPX
    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Links.aspx.cs" Inherits="admin_Links" %> 
    <%@ Register Assembly="RadGrid.Net2" Namespace="Telerik.WebControls" TagPrefix="radG" %> 
    <!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>Untitled Page</title> 
    </head> 
    <body> 
        <form id="form1" runat="server">  
        <div> 
            <radG:RadGrid ID="RadGrid1" runat="server" AllowFilteringByColumn="True" AllowPaging="True" 
                AllowSorting="True" DataSourceID="SqlDataSource1" EnableAJAX="True" GridLines="None" OnDeleteCommand="RadGrid1_DeleteCommand" OnUpdateCommand="RadGrid1_UpdateCommand">  
    <MasterTableView CommandItemDisplay="Top" DataSourceID="SqlDataSource1" AutoGenerateColumns="False" DataKeyNames="LinkID"><Columns> 
    <radG:GridEditCommandColumn></radG:GridEditCommandColumn> 
    <radG:GridBoundColumn DataField="LinkID" DataType="System.Int32" UniqueName="LinkID" SortExpression="LinkID" Visible="False" HeaderText="LinkID"></radG:GridBoundColumn> 
    <radG:GridBoundColumn DataField="Text" UniqueName="Text" SortExpression="Text" HeaderText="Link Text"></radG:GridBoundColumn> 
    <radG:GridBoundColumn DataField="URL" UniqueName="URL" SortExpression="URL" HeaderText="URL"></radG:GridBoundColumn> 
    <radG:GridBoundColumn DataField="Clicks" DataType="System.Int32" UniqueName="Clicks" AllowFiltering="False" SortExpression="Clicks" HeaderText="Clicks"></radG:GridBoundColumn> 
    <radG:GridBoundColumn DataField="Priority" DataType="System.Int32" UniqueName="Priority" AllowFiltering="False" SortExpression="Priority" HeaderText="Priority"></radG:GridBoundColumn> 
    <radG:GridCheckBoxColumn DataField="Enabled" DataType="System.Boolean" UniqueName="Enabled" AllowFiltering="False" SortExpression="Enabled" HeaderText="Enabled"></radG:GridCheckBoxColumn> 
    <radG:GridButtonColumn UniqueName="column" Text="Delete" CommandName="Delete" ConfirmText="Are you sure you want to delete this row?"></radG:GridButtonColumn> 
    </Columns> 
    <EditFormSettings EditFormType="WebUserControl" UserControlName="editors/Links.ascx">  
        <EditColumn UniqueName="EditCommandColumn1">  
        </EditColumn> 
    </EditFormSettings> 
    <ExpandCollapseColumn Visible="False">  
    <HeaderStyle Width="19px"></HeaderStyle> 
    </ExpandCollapseColumn> 
    <RowIndicatorColumn Visible="False">  
    <HeaderStyle Width="20px"></HeaderStyle> 
    </RowIndicatorColumn> 
    </MasterTableView> 
    </radG:RadGrid><asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:wtoConnectionString %>" 
                SelectCommand="SELECT * FROM [tourism_Links]"></asp:SqlDataSource> 
        </div> 
        </form> 
    </body> 
    </html> 
     

    LINKS.ASCX
    <%@ Control Language="C#" AutoEventWireup="true" CodeFile="Links.ascx.cs" Inherits="admin_editors_Links" %> 
    <%@ Register Assembly="RadComboBox.Net2" Namespace="Telerik.WebControls" TagPrefix="radC" %> 
    <table border="0" cellpadding="0" cellspacing="0" style="width: 800px">  
        <tr> 
            <td style="width: 150px; height: 24px">  
                Link Text</td> 
            <td style="width: 650px; height: 24px">  
                <asp:TextBox ID="TextBox1" Text='<%# Eval("Text") %>' runat="server" Columns="30" MaxLength="30"></asp:TextBox> 
                <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="TextBox1" 
                    ErrorMessage="Link text required.">*</asp:RequiredFieldValidator></td>  
        </tr> 
        <tr> 
            <td style="width: 150px">  
                URL</td> 
            <td style="width: 650px">  
                <asp:TextBox ID="TextBox2" Text='<%# Eval("URL") %>' runat="server" Columns="30" MaxLength="30"></asp:TextBox> 
                <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="TextBox2" 
                    ErrorMessage="RequiredFieldValidator">*</asp:RequiredFieldValidator></td>  
        </tr> 
        <tr> 
            <td style="width: 150px">  
                Priority</td> 
            <td style="width: 650px">  
                <radC:RadComboBox ID="RadComboBox1" runat="server" OnPreRender="RadComboBox1_PreRender" 
                    Skin="Outlook" SkinsPath="~/RadControls/ComboBox/Skins" Width="150px">  
                    <Items> 
                        <radC:RadComboBoxItem runat="server" Text="0" Value="0" /> 
                        <radC:RadComboBoxItem runat="server" Text="1" Value="1" /> 
                        <radC:RadComboBoxItem runat="server" Text="2" Value="2" /> 
                        <radC:RadComboBoxItem runat="server" Text="3" Value="3" /> 
                    </Items> 
                </radC:RadComboBox> 
            </td> 
        </tr> 
        <tr> 
            <td style="width: 150px">  
                Enabled</td> 
            <td style="width: 650px">  
                <asp:CheckBox ID="CheckBox1" runat="server" OnPreRender="CheckBox1_PreRender" /></td>  
        </tr> 
        <tr> 
            <td style="width: 150px">  
                &nbsp;</td> 
            <td style="width: 650px">  
            </td> 
        </tr> 
        <tr> 
            <td style="width: 150px; height: 39px;" valign="top">  
                <asp:ImageButton ID="btnUpdate" runat="server" CommandName="Update" ImageUrl="~/RadControls/Grid/Skins/Update.gif" /> 
                <asp:ImageButton ID="btnCancel" 
                        runat="server" CausesValidation="False" CommandName="Cancel" ImageUrl="~/RadControls/Grid/Skins/Cancel.gif" /></td>  
            <td style="width: 650px; height: 39px;">  
                <asp:ValidationSummary ID="ValidationSummary1" runat="server" /> 
                <asp:TextBox ID="TextBox3" runat="server" Text='<%# Eval("Priority") %>' Visible="False"></asp:TextBox> 
                <asp:TextBox ID="TextBox4" runat="server" Text='<%# Eval("Enabled") %>' Visible="False"></asp:TextBox></td>  
        </tr> 
    </table> 
     

    LINKS.ASCX.CS
    using System;  
    using System.Data;  
    using System.Configuration;  
    using System.Collections;  
    using System.Web;  
    using System.Web.Security;  
    using System.Web.UI;  
    using System.Web.UI.WebControls;  
    using System.Web.UI.WebControls.WebParts;  
    using System.Web.UI.HtmlControls;  
     
    public partial class admin_editors_Links : System.Web.UI.UserControl  
    {  
        protected void Page_Load(object sender, EventArgs e)  
        {  
     
        }  
     
        protected void RadComboBox1_PreRender(object sender, EventArgs e)  
        {  
            if (TextBox3.Text.Length > 0)  
                RadComboBox1.SelectedIndex = Convert.ToInt32(TextBox3.Text);  
        }  
     
        protected void CheckBox1_PreRender(object sender, EventArgs e)  
        {  
            if (TextBox4.Text.Length > 0)  
                CheckBox1.Checked = Convert.ToBoolean(TextBox4.Text);  
        }  
    }  
     


    So far I haven't had a single problem with bound CheckBoxes using this method.

  • Posted on Oct 4, 2007 (permalink)

    I ran across the same problem and have created a simple solution, which is most easy to use:

    Create a usercontrol with the following code:

    myCheckbox.ascx:
    <%@ Control Language="C#" AutoEventWireup="true" CodeFile="myCheckBox.ascx.cs" Inherits="Controls_myCheckBox" %>
    <asp:CheckBox ID="CheckBox1" runat="server" />

    myCheckbox.ascx.cs:

    public partial class Controls_myCheckBox : System.Web.UI.UserControl
    {

        private bool m_checked = false;

        public object Checked
        {
            get { return m_checked; }
            set
            {
                if (value.GetType() == DBNull.Value.GetType())
                    m_checked = false;
                else if (value == null)
                    m_checked = false;
                else if (value.GetType() == typeof(bool))
                    m_checked = (bool)value;
                else
                    m_checked = false;
            }
        }


        protected void Page_Load(object sender, EventArgs e)
        {
            m_checked = CheckBox1.Checked;
        }

        protected void Page_PreRender()
        {
            CheckBox1.Checked = m_checked;
        }
    }

    In your aspx page you need to register that control in the head:
    <%@ Register Src="~/Controls/myCheckBox.ascx" TagName="myCheckbox" TagPrefix="myChk" %>


    And now - you can use it like a regular checkbox without the Null problem:
    <myChk:myCheckbox ID="chkMyBox" runat="server" Checked='<%# Bind("MyField") %>' />

    Hope this helps!


    Fabian


  • CityArchitect avatar

    Posted on Oct 14, 2007 (permalink)

    Fabian,

    Thank you. I've had this problem for a very long time and this fixes it for me.

    A clean and elegant solution.

    Steve

  • Andrew avatar

    Posted on Nov 19, 2007 (permalink)

    Fantastic Fabian,

    I was looking everywhere for a simple solution. 

    thanks

  • Posted on Jan 11, 2008 (permalink)

    thanks. as this helps a lot.
    I use almost the same technique with the dropdownlist and calendar controls for asp.net and ajax.
    I have added a post on my blog for this, and put up formatted source code, as this is a generic solution for asp.net data controls
    http://oudinia.blogspot.com

  • kyle avatar

    Posted on Mar 1, 2008 (permalink)

    This works great to get around the casting error. But when using LINQ to SQL you will get an error on insert because the property is of object type. Havent figured a way around this one yet. :(

  • Posted on Jul 17, 2008 (permalink)

    Wala lang!

  • Posted on Apr 22, 2009 (permalink)

    I stumbled into the same problem today.
    Using the big G I found a lot of solutions - but most of them work only for eval (read only) or a specific framework.
    And Google brought up this thread also (I didn't search here - since this problem is not telerik related).

    My solution (in a webapp) looks like this:
    Create a Custom Web Control (NOT a user...).
    Derive from checkbox and remove almost all code and set default property to Checked  - so the class should look like this:
        [DefaultProperty("Checked")]  
        [ToolboxData("<{0}:NullChkBox runat=server></{0}:NullChkBox>")]  
        public class NullChkBox : CheckBox {  
            [Bindable(true)]  
            [Localizable(true)]
    CODE BELOW COMES THIS PLACE
        }  
    }  
     
    Next override the Checked property like this:
    public new object Checked {  
        get {  
            return base.Checked;  
        }  
        set {  
            if (value == null || value is DBNull) {  
                base.Checked = false;  
                return;  
            }  
            string strComp = value.ToString().ToUpper();  
            if (strComp == "1" || strComp == "TRUE") {  
                base.Checked = true;  
            }  
            else {  
                base.Checked = false;  
            }  
        }  
    }  
     
    Be sure to use NEW instead of override.
    By the way - if not copying from here the easy way to do it is:
    type override and hit blank - choose what you want (in this case Checked) from Intellisense and hit tab.
    You get the almost read implementation. In this case only the set has to be changed.

    After a rebuild you should find your control in the tools.
    Drag it on your form and notice the following line inserted on top of the page:

    <%@ Register Assembly="YOUR_ASSEMBLY" Namespace="YOUR.NAMESPACE" TagPrefix="cc1" %> 
    You can now simply use this control on every page (dragging it there) or by typing it in after you added the line on top of your file.
    Since I use a lot of custom controls in my project I prefer the following approach.
    Copy the above line to your web.config and modify it there. So the result should look like this:
    <pages....> 
    <controls> 
    ....  
    <add assembly="YOUR_ASSEMBLY" namespace="YOUR.NAMESPACE" tagPrefix="myCtrls" /> 
    Take care - web.config is case sensitive!
    From now on you can simply type in your pages <myCtrls: and let Intellisense do the rest :)

    Last not least - a checkbox is not a content control - so normally you would define it like <asp:Checkbox .... /> instead of using a closing tag.
    To have this with your "nullable checkbox" also go back to your class and change
    [ToolboxData("<{0}:NullChkBox runat=server></{0}:NullChkBox>")]  
    TO  
    [ToolboxData("<{0}:NullChkBox runat=server />")]  
    Now you are done with your control :)

    HTH

    Manfred

  • Sebastian Sebastian admin's avatar

    Posted on Apr 23, 2009 (permalink)

    Hello ManniAT,

    Thank you for sharing your solution in this public forum thread. Thus you can help other community members who are searching for a solution to bypass the error on init insertion using asp Checkbox with binding expression in RadGrid edit form. Your custom control indeed is reusable and will spare them the time to handle the init insert operation manually and provide default state for the checkbox as explained in the relevant paragraph of this help topic.

    I updated your Telerik points for the feedback you shared in this post.

    Kind regards,
    Sebastian
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.

  • Posted on Apr 23, 2009 (permalink)

    My Problem with the help solution is (beside that I want to avoid code behind when ever possible) that I do sometimes let's say "dynamic development" - or as others may call it "RAD TREE coding"
    Rough And Dirty TRial and Error Evolutionary coding :)
    I guess Scott Hanselmann once called this "always forward with running code".

    To be precise - I do something - check if it works (looks) like expected; have feedback from involved people and change it and so on.
    This results in adding field - or removing them, changing types and so forth.
    With declarative binding (no code behind) this avoids changing the code - I simply drop in a field or remove it - just as I need it at the moment.

    And I like to share solutions - as long as I'm able to.
    Our main customers are from the "high end industrial sector" - so most of the (sometimes real coll) things we do are "top secret" and covered with some NDAs.
    But some details (like in this case) are out of the scope of this agreements - so I can share them.
    Since I myself am also happy when I can find some working solution for a problem - why shouldn't I offer something I solved to other people.

    And by the way - the things changed. In my early days (ASM, C, C++) was often more frustrating than anything else.
    I posted some code - and the comments looked like "you should use this operator and when changing the loop to xxxx you save 5 cycles..." :) Which resulted sometimes in endless (and form the point of the problem useless) discussions about how the get the last CPU cycle saved - in a function which is called once when a users presses a button :)
    Anyhow - in the current days the things changed - comments are much more constructive and sharing code makes much more fun.
    And when I finally get a comment like "thank's dude - you solved my problem" this is far worth the hour I spent to "prepare and share" the code.

    And this in fact is what I like most with your support.
    A lot of questions are answered in a manner that helps you solve the problem - a little snippet here, a working sample there - you do really a great job.
    And your support answered much more questions than I asked. Simply by using the search and finding a thread which solves my problem.
    One of the great things about your community - you are not the kind of organization which answers questions with "this is not in the scope of our product...". Like this thread here - it has absolutely nothing to do with a "telerik related problem" - but the members (telerik employees as well as customers) help to solve the problem.
    And the community here becomes better and better - in the early days I came here only when I really had a "for sure telerik problem" - but now it tends to be more and more a place to find common answers.
    Great work!!

    Regards

    Manfred

  • Sebastian Sebastian admin's avatar

    Posted on Apr 27, 2009 (permalink)

    Hello ManniAT,

    Thank you for the nice words about our constant effort to improve the support service we provide and help as much community members as possible by expanding the available support resources and adding new demos/help topics/kb articles/etc. We are also happy that the Telerik community is becoming more active and vocal during the years because the feedback we receive will surely not remain unnoticed and will help us make our controls even more powerful and feature-rich.

    It is encouraging that more and more people in the forums are able to find the answers to their questions either by searching the vast resources on our site or getting help from other mate developers.

    I am glad to hear that you are willing to share your own solutions in our forums with other people and contribute to our community as well.

    Best regards,

    Sebastian
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.

  • Posted on Apr 27, 2009 (permalink)

    Hi Sebastian,

    of course I have to speak "nice words" about your support.
    This support made me a loyal telerik customer.
    In my "early days" with your controls they have been a product for me like all the others I used.
    The difference became visible when I had my first "problems" - most of all because of my missing skills with your controls I had to ask a lot of questions - and I always got an answer - or to be precise - I got a solution.
    And even in times when you competitors have been a little bit "more featured" I never thought about using a different product.
    Simply because I knew that here (at telerik) I will never be left alone with my problems.

    A last thing - if you would ask me if I know anything better than the RadControls for ASP.NET I can answer YES
    Better than the controls itself is the support behind it :)

    And a lot of my postings here have a pure selfish reason - I know writing here means being heard and often it comes out as "getting a feature implemented".

    Thanks again for this

    Manfred

  • jimmie avatar

    Posted on Jun 15, 2009 (permalink)

    Rowland- I used this code and it threw the same exception on the insert line (last line)

    e.Canceled =

    True

     

     

    Dim newValues As System.Collections.Specialized.ListDictionary = New System.Collections.Specialized.ListDictionary()

     

    newValues(

    "isCompleteCB") = False

     

    e.Item.OwnerTableView.InsertItem(newValues)

    Has anyone else experienced this behavior

  • Ad Kam avatar

    Posted on Jul 24, 2009 (permalink)

    Fabian,

    I tried to use your control in VB format but it doesn't work. Do you have the VB format?

    Thanks

  • Posted on Nov 13, 2009 (permalink)

    Hi,
    Paleman

    Sir i want to know that how to find the button inside this

    <EditFormSettings EditFormType="Template">
                                <FormTemplate> </FormTemplate>
    </EditFormSettings>

    My problem is that i have three things in dropdownlist and  one radgrid
    1) Pending Products
    2) All Products(pending and approved)
    3) All approved products

    and in the  Form Template  the same structure is used  for all these option.so i want to hide the button (BtnApproved) if the selction is approved product.what should i do to find this control inside  form template. you have posted this article but its not working
     

  • Posted on Nov 13, 2009 (permalink)

    Hello Amit,

    You can access the button in the formtemplate, in the ItemDataBound event of the grid and hide it based on your condition:
    c#:
     protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e) 
        { 
            if (e.Item is GridEditFormItem && e.Item.IsInEditMode) 
            { 
                GridEditFormItem editItem = (GridEditFormItem)e.Item; 
                if(approved product) // replace with your condition 
                { 
                   Button btn = (Button)editItem.FindControl("BtnApproved"); 
                   btn.Visible = false
                } 
            } 
       } 

    Thanks
    Princy.

  • haresh kumbhar avatar

    Posted on Feb 20, 2010 (permalink)

    dear friend,
    thanx for u r supporting it is working properly, and next time also help me for further query

  • Jørn Topnes avatar

    Posted on Aug 23, 2010 (permalink)

    I also ran into this problem using a custom FormTemplate with a GridCheckBoxColumn bound to a custom generated datasource containing data from several OpenAccess linq queries. I tried a few solutions in this thread, but couldn't get them to work properly in my scenario. But then I got it working by setting the GridCheckBoxColumn's DefaultInsertValue to a value. This value should probably be a part of the constructor to prevent exceptions when the columns type can't handle default nulls?

    Best regards,
    Jørn

  • Joe Wortman avatar

    Posted on Oct 22, 2010 (permalink)

    Thanks Fabian,

    Very simple solution.   Much better than the work arounds I've read everywhere else.   Be nice if it just worked, but this is at least a simple workaround!

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET > Grid > asp:Checkbox in FormTemplate. "Specified Cast is Invalid"