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

Boolean field one-click Edit

2 Answers 47 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Rick
Top achievements
Rank 1
Rick asked on 03 Aug 2012, 07:44 PM
  • I am using MS Visual Studio 2010 in a 3.5 environment.
  • I am using Microsoft Vista (32 bit)
  • The database is currently located on an SQL 2005 server.
  • I am using RadGrid & tools, version 2012.1.411.35
  • I am using both Chrome (18.0.1025.168) and Internet Explorer (8.0.7600.16385)
  • I am programming in VB.net

I have a rad grid with three boolean fields in it.  The boolean fields show up as checkboxes.  I would like the end user to be able to click these and toggle the value WITHOUT having to click the Edit command first.

How can I do this?

2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 06 Aug 2012, 06:14 AM
Hi Berto,

I suppose you have set the 'AutoGenerateColumn' property to 'true' which is true by default. Then the Boolean fields will be shown as GridCheckBoxColumn which will not be enabled in the View Mode. In-order to toggle the checkbox value without clicking the edit command, make it enabled in the view mode itself using the following code snippet.

VB:
Protected Sub RadGrid1_ItemDataBound(sender As Object, e As Telerik.Web.UI.GridItemEventArgs)
    If TypeOf e.Item Is GridDataItem Then
        Dim ditem As GridDataItem = DirectCast(e.Item, GridDataItem)
        Dim chk As CheckBox = DirectCast(ditem("DataField").Controls(0), CheckBox)
                ' Access the GridCheckBoxColumn using DataField name
        chk.Enabled = True
    End If
End Sub

Thanks,
Princy.
0
Rick
Top achievements
Rank 1
answered on 06 Aug 2012, 05:33 PM
Thanks Bob,

I ended up changing the column to a template column and calling a procedure.

<telerik:GridTemplateColumn HeaderText="Flag Briefcase<br/>(With DLB)" FilterControlAltText="Filter Currency_BriefcaseUsed column" 
    UniqueName="Currency_BriefcaseUsed">
    <HeaderStyle HorizontalAlign="Center" VerticalAlign="Bottom"></HeaderStyle>
    <ItemStyle HorizontalAlign="Center"></ItemStyle>
    <EditItemTemplate>
        <asp:CheckBox ID="CheckBoxA" runat="server" Checked='<%# Bind("Currency_BriefcaseUsed") %>' />
    </EditItemTemplate>
    <ItemTemplate>
        <asp:CheckBox ID="CheckBoxB" runat="server" Checked='<%# Bind("Currency_BriefcaseUsed") %>' OnCheckedChanged="UpdateBriefcaseFlag" autopostback="true"/>
    </ItemTemplate>
</telerik:GridTemplateColumn>

My procedure reads the fields and runs an update query:

Public Sub UpdateBriefcaseFlag(sender As Object, e As System.EventArgs)
    Dim cmdUpdate As SqlCommand
    Dim cell As GridTableCell = sender.parent
    Dim data As GridDataItem = cell.Parent
    Dim ID As String = data.GetDataKeyValue("Currency_CountryCode")
    Dim Flag As Boolean = data.GetDataKeyValue("Currency_BriefcaseUsed")
 
    If Flag = False Then
        Flag = True
    Else
        Flag = False
    End If
    Using connection As SqlConnection = New SqlConnection("Data Source=W-SQL04.dlbassociates.com;Initial Catalog=DonPlanner;Integrated Security=SSPI")
        connection.Open()
        cmdUpdate = New SqlCommand("UPDATE Currency_LatestConversions_TBL SET Currency_BriefcaseUsed = @Currency_BriefcaseUsed WHERE Currency_CountryCode = @Currency_CountryCode", connection)
        cmdUpdate.Parameters.AddWithValue("Currency_CountryCode", ID)            'Country Code
        cmdUpdate.Parameters.AddWithValue("Currency_BriefcaseUsed", Flag)            'Currency Description
        cmdUpdate.ExecuteNonQuery()
        connection.Close()
    End Using
End Sub

Tags
Grid
Asked by
Rick
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Rick
Top achievements
Rank 1
Share this question
or