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

GridClientSelectColumn/CheckBoxColumn

1 Answer 132 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Joel
Top achievements
Rank 2
Joel asked on 16 Dec 2009, 09:07 PM
I am not sure of the suggested method on how to accomplish this.  Any assistance would be greatly appreciated.

I have a grid bound to a boolean field.  If the item value is 1, I want he checkbox checked and read only (GridCheckBoxColumn would work here).  If the item value is 0, I want the checkbox enabled (GridCheckBoxColumn doesn't seem to work for this) and a postback when the user checks the box so I can update the database and rebind the two grids on the page.

In short, I want it so checks can never be removed, only added, and only one item checked per postback.  Grid is bound with NeedDataSource event.

Any suggestions?


Here is what I have now.  When it is done, I only want to have one column of checkboxes, the three below are all tests.

            <telerik:RadGrid runat="server" ID="RadGrid1" AutoGenerateColumns="false" 
                GridLines="None" Height="500" BorderWidth="0" AllowSorting="true" Style="outline: none" 
                ShowGroupPanel="false" AllowPaging="true" AllowFilteringByColumn="false"
                <ClientSettings Scrolling-AllowScroll="True" Scrolling-UseStaticHeaders="true" Selecting-AllowRowSelect="true" 
                    EnablePostBackOnRowClick="true"  EnableRowHoverStyle="true" 
                    ClientEvents-OnRowSelected="RowSelected" > 
                </ClientSettings> 
                <MasterTableView TableLayout="Fixed"  GroupLoadMode="Client" DataKeyNames="job_id" > 
                    <Columns> 
                    <telerik:GridCheckBoxColumn DataField="isChecked" ReadOnly="false" HeaderText="My Job1" HeaderStyle-Width="60" UniqueName="mycheck1" ></telerik:GridCheckBoxColumn> 
                    <telerik:GridClientSelectColumn HeaderText="My Job2"  HeaderStyle-Width="60" UniqueName="mycheck2"></telerik:GridClientSelectColumn> 
                    <telerik:GridTemplateColumn HeaderText="Check/UnCheck"   UniqueName="TemplateColumn"
                          <EditItemTemplate> 
                            <asp:CheckBox id="editChkBox" runat="server" AutoPostBack="true" 
                             Checked='<%# Bind("ischecked") %>' Enabled="true"
                            </asp:CheckBox> 
                          </EditItemTemplate> 
                          <ItemTemplate> 
                             <asp:CheckBox id="defaultChkBox" runat="server" Enabled="true" 
                             Checked='<%# Eval("ischecked") %>'
                           </asp:CheckBox> 
                          </ItemTemplate> 
                        </telerik:GridTemplateColumn> 
                    <telerik:GridBoundColumn DataField="user_id" Headertext="userid" Visible="false"></telerik:GridBoundColumn> 
                        <telerik:GridBoundColumn DataField="username" HeaderText="Username" HeaderStyle-Width="120px"
                        </telerik:GridBoundColumn> 
                        <telerik:GridBoundColumn DataField="Title" HeaderText="Title" > 
                        </telerik:GridBoundColumn> 
                    </Columns> 
                </MasterTableView> 
            </telerik:RadGrid> 

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 17 Dec 2009, 05:59 AM
Hello Joel,

Try out the following code using a GridCheckboxColumn to achieve the required sceanrio:

aspx:
<telerik:GridCheckBoxColumn DataField="Condition" UniqueName="CheckBoxColumn" HeaderText="CheckBox Column"
</telerik:GridCheckBoxColumn> 

c#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
    { 
        if (e.Item is GridDataItem) 
        { 
            GridDataItem item = (GridDataItem)e.Item; 
            CheckBox chk = (CheckBox)item["CheckBoxColumn"].Controls[0]; 
            chk.Enabled = !chk.Checked; 
            chk.AutoPostBack = true
 
        } 
    } 

Hope this helps..
Princy.
Tags
Grid
Asked by
Joel
Top achievements
Rank 2
Answers by
Princy
Top achievements
Rank 2
Share this question
or