简体   繁体   中英

RadGrid get [GridClientSelectColumn] selected Items

I would like to loop and get all the selected checkbox items from [GridClientSelectColumn], but there has no any row return even the column checked. Thanks for helping.

.aspx

<telerik:RadGrid ID="RadGrid_1" runat="server" AllowPaging="True" 
    AutoGenerateColumns="False" CellSpacing="0" GridLines="None" 
    Skin="Outlook" AllowMultiRowSelection="True" AllowSorting="True">

    <ClientSettings>
        <Selecting AllowRowSelect="True" />
    </ClientSettings>

<Columns>
    <telerik:GridClientSelectColumn FilterControlAltText="Filter template_selected column" 
        UniqueName="template_selected">
    </telerik:GridClientSelectColumn>
    <telerik:GridBoundColumn FilterControlAltText="Filter ID column" 
        HeaderText="PHID" UniqueName="ID" Visible="False" 
        DataField="PHID">
    </telerik:GridBoundColumn>
    <telerik:GridBoundColumn FilterControlAltText="Filter Title column" 
        HeaderText="Title" UniqueName="Title" DataField="Title">
    </telerik:GridBoundColumn>
</columns>

.aspx.cs

protected void btn_Click(object sender, EventArgs e)
{
    string id;
    bool chec;
    foreach (GridDataItem item in RadGrid_1.SelectedItems)
    {
        CheckBox chk = (CheckBox)item["template_selected"].Controls[0];
        title = item["Title"].Text;
        chec = chk.Checked;
    }
}

I'm not sure what version of Telerik you're using, but I do know that regardless of the version, the RadGrid can be quite picky.

The demo on the Telerik website for selecting items is as follows:

http://demos.telerik.com/aspnet-ajax/grid/examples/functionality/selecting/row-selection/defaultcs.aspx

Here's the markup that they use for the demo.

 <telerik:RadGrid ID="RadGrid1" DataSourceID="SqlDataSource1" AllowMultiRowSelection="true"
    runat="server" AllowSorting="True" GridLines="None" OnPreRender="RadGrid1_PreRender">
    <MasterTableView>
        <Columns>
            <telerik:GridClientSelectColumn UniqueName="ClientSelectColumn">
            </telerik:GridClientSelectColumn>
        </Columns>
    </MasterTableView>
    <ClientSettings EnableRowHoverStyle="true">
        <Selecting AllowRowSelect="True"></Selecting>
        <ClientEvents OnRowMouseOver="RowMouseOver" />
    </ClientSettings>
</telerik:RadGrid>

Based on the above, I would check:

  1. Are you using a MasterTableView ? If you're not, you might want to try that approach even if you don't have detail tables. If RadGrid_1.MasterTableView.SelectedItems doesn't work, you can try iterating through RadGrid_1.MasterTableView.Items and check for items where item.Selected is true.

  2. I'm going to assume that </column> in your post above is just a typo, but it should be </Columns>

Hope that helps. (Incidentally, the demo code on their website is incorrect because they don't even define all of the columns in the grid within their "live" sample code, LOL.)

Here is what I do:

 For Each griditem1 As GridDataItem In RadGrid.MasterTableView.Items
            If griditem1.Selected Then
                Dim DocumentID As String = griditem1.OwnerTableView.DataKeyValues(griditem1.ItemIndex)("DocID").ToString
                
            End If

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM