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

Need to show a non-readonly (editable) checkbox inside a grid

2 Answers 73 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Manoj
Top achievements
Rank 1
Manoj asked on 26 Jan 2009, 01:39 PM
Hi,

I am using a rad grid and wish to show a checkbox in it. I am using GridCheckBoxColumn for showing this checkbox and setting its DataField property to the column of the table so that this checkbox shows values from the database.

The problem I am facing is that the checkbox is shown readonly. I would like the user to be able to change the value of the checkbox by clicking it. And after user clicks the checkbox I would like to postback to server and update the server.

If I use inline editing then I do not wish to show the "Edit" links so that user can directly edit the checkbox without first clicking edit link.

Can someone please help...

Thanks,
- Manoj

2 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 27 Jan 2009, 05:20 AM
Hi Manoj,

I would suggest you to use a GridTemplateColumn with CheckBox in its ItemTemplate since GridCheckBoxColumn is ReadOnly in normal mode. In the CheckChanged event of the CheckBox you can perform the Update operation.

ASPX:
<telerik:GridTemplateColumn UniqueName="TempCol" AllowFiltering="False" DataField="Discontinued"  HeaderText="TempCol"  > 
                        <ItemTemplate> 
                            <asp:CheckBox ID="CheckBox" AutoPostBack="true" runat="server" Checked='<%#Bind("Discontinued") %>'   OnCheckedChanged="CheckBox_CheckedChanged" /> 
                        </ItemTemplate> 
                       </telerik:GridTemplateColumn> 


CS:
protected void CheckBox_CheckedChanged(object sender, EventArgs e) 
    { 
        CheckBox chkbx = (CheckBox)sender; 
        // to access the GridDataItem; 
        GridDataItem item = (GridDataItem)chkbx.NamingContainer; 
        // perform the Update operation 
    } 

Thanks
Shinu
0
Manoj
Top achievements
Rank 1
answered on 02 Feb 2009, 07:49 AM
Hi Shinu,

Thanks for your reply. It completely solved the problem I was having.

Thanks!
- Manoj
Tags
Grid
Asked by
Manoj
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Manoj
Top achievements
Rank 1
Share this question
or