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

how to selected the selected item in Grid?

1 Answer 56 Views
Grid
This is a migrated thread and some comments may be shown as answers.
liu qingshui
Top achievements
Rank 1
liu qingshui asked on 14 Apr 2010, 09:46 AM
<telerik:RadGrid ID="GridDepartment" runat="server" OnPageIndexChanged="GridDepartment_PageIndexChanged" 
                                                                                            OnPageSizeChanged="GridDepartment_PageSizeChanged" OnSortCommand="GridDepartment_SortCommand" 
                                                                                            OnItemDataBound="GridDepartment_ItemDataBound"  OnItemCommand="GridDepartment_ItemCommand"
                                                                                            <MasterTableView AutoGenerateColumns="False" AllowPaging="True" AllowSorting="True" 
                                                                                                GroupsDefaultExpanded="false" PageSize="20"
                                                                                                <Columns> 
                                                                                                    <telerik:GridTemplateColumn> 
                                                                                                        <ItemTemplate> 
                                                                                                            <asp:CheckBox ID="checkBox" runat="server"  AutoPostBack="true"/> 
                                                                                                        </ItemTemplate> 
                                                                                                    </telerik:GridTemplateColumn> 
                                                                                                    <telerik:GridBoundColumn DataField="DspName" HeaderText="姓名" UniqueName="DspName" 
                                                                                                        SortExpression="DspName"
                                                                                                    </telerik:GridBoundColumn> 
                                                                                                    <telerik:GridBoundColumn DataField="DeptName" HeaderText="部门" UniqueName="DeptName" 
                                                                                                        SortExpression="DeptName"
                                                                                                    </telerik:GridBoundColumn> 
                                                                                                     
                                                                                                </Columns> 
                                                                                                <GroupByExpressions> 
                                                                                                    <telerik:GridGroupByExpression> 
                                                                                                        <SelectFields> 
                                                                                                            <telerik:GridGroupByField FieldName="DeptName" HeaderText="部门" /> 
                                                                                                        </SelectFields> 
                                                                                                        <GroupByFields> 
                                                                                                            <telerik:GridGroupByField FieldName="DeptName" HeaderText="部门" SortOrder="Descending" /> 
                                                                                                        </GroupByFields> 
                                                                                                    </telerik:GridGroupByExpression> 
                                                                                                </GroupByExpressions> 
                                                                                            </MasterTableView> 
                                                                                            <ClientSettings> 
                                                                                                <Selecting AllowRowSelect="True" /> 
                                                                                            </ClientSettings> 
                                                                                        </telerik:RadGrid> 




I don't know how to get the information when users click the CheckBox.
For example,when users click the first two,how can I know the choosed items?
Please have a look at the attachment.


1 Answer, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 14 Apr 2010, 10:14 AM
Hi,

The following code shows how to access the corresponding row values in CheckedChanged event where the CheckBox is placed in ItemTemplate.

C#:
 
    protected void checkBox_CheckedChanged(object sender, EventArgs e) 
    { 
        CheckBox chkBox = (CheckBox)sender; 
        GridDataItem item = (GridDataItem)chkBox.NamingContainer; 
        string value = item["DeptName"].Text; 
        Response.Write(value); 
    } 

Thanks,
Princy.
Tags
Grid
Asked by
liu qingshui
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or