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

Radgrid checkbox client-side row selection

3 Answers 848 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Raja Rajeswari Mohan Venkataraman
Top achievements
Rank 1
Raja Rajeswari Mohan Venkataraman asked on 24 Aug 2011, 09:07 PM
Hi,

I have a radgrid in my .aspx page. I'm having a checkbox inside the  GridTemplateColumn.  On the checkbox onclick event I am calling the javascript function  chkRowSelection(this).   In that function I need to get the values of the radgrid ClientDataKeyNames="SRC,SER,BAND,XLA,XLG,RGN,STT,EIP,SVC,FRQ,FTA"  for the row checked. Could you please help me to achieve this.

<

 

telerik:RadGrid ID="grdResult" runat="server" Width="900px"

 

 

AllowMultiRowSelection="True" AllowSorting="True" Height="400px"

 

 

style="margin-right: 1px" Skin="WebBlue" GridLines="None" AllowPaging="true" PageSize="100">

 

 

<PagerStyle Position="Top" />

 

 

<MasterTableView AllowPaging="true" AutoGenerateColumns="true" AllowMultiColumnSorting="true" ClientDataKeyNames="SRC,SER,BAND,XLA,XLG,RGN,STT,EIP,SVC,FRQ,FTA" Font-Size="Smaller" PageSize="100" >

 

 

<Columns>

 

 

<telerik:GridTemplateColumn UniqueName="SEL">

 

 

<HeaderTemplate>

 

 

<asp:CheckBox runat="server" ID="ChkAll" ToolTip="Click to select all" onclick="javascript:SelectAllCheckboxes(this);" />

 

 

</HeaderTemplate>

 

 

<HeaderStyle Width="20px" />

 

 

<ItemTemplate>

 

 

<asp:CheckBox runat="server" ID="SEL" onclick="javascript:chkRowSelection(this);" />

 

 

</ItemTemplate>

 

 

<ItemStyle Width="20px" />

 

 

</telerik:GridTemplateColumn>

 

 

</Columns>

 

 

<ItemStyle Wrap="false" />

 

 

<HeaderStyle Wrap="False" />

 

 

</MasterTableView>

 

 

<HeaderStyle Wrap="False" />

 

 

<ClientSettings ReorderColumnsOnClient="true" EnableRowHoverStyle="False" AllowColumnsReorder="true" >

 

 

<Scrolling AllowScroll="True" UseStaticHeaders="true" />

 

 

<Selecting AllowRowSelect="true" />

 

 

<Resizing EnableRealTimeResize="true" ResizeGridOnColumnResize="true" AllowColumnResize="true"/>

 

 

<ClientEvents OnRowContextMenu="grdResult_RowSelected" OnRowClick="RowClicked" />

 

 

</ClientSettings>

 

 

<Headerstyle Width="65px" />

 

 

<PagerStyle Mode="NextPrevAndNumeric" ></PagerStyle>

 

</

 

telerik:RadGrid>

javascript:

 

 

function chkRowSelection(chkBox)
{
 // need to get the values of the ClientDataKeyNames="SRC,SER,BAND,XLA,XLG,RGN,STT,EIP,SVC,FRQ,FTA"  for the selected row in this function.
}

Thanks,
Raji

 

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 25 Aug 2011, 05:13 AM
Hello Raja,

You can attach "onclick" function by accessing the CheckBox from server side and pass the row index as shown below.

C#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{  
    if (e.Item is GridDataItem)
   {
       GridDataItem dataItem = (GridDataItem)e.Item;
       CheckBox chkbox = (CheckBox)dataItem.FindControl("ChkAll");
       int index = dataItem.ItemIndex;
       chkbox.Attributes.Add("onclick", "checked('" + index + "');");
   }
}

Javascript:
function checked(index)
{
   var row = $find('<%= RadGrid1.ClientID %>').get_masterTableView().get_dataItems()[index];
   alert(row.getDataKeyValue("ID"));//DataKeyName
}
Note: Set ClientDataKeyNames as ID.

Thanks,
Princy.
0
ASTI
Top achievements
Rank 1
answered on 19 Oct 2011, 03:24 PM
Hello,
 I got a radgrid simmilar with checkbox inside of GridTemplateColumn, and I want to get every selected row Id on server side, for that I wrote the followed code:

            <telerik:RadGrid ID="RadGridValidarHoras" runat="server"

                AllowMultiRowSelection="True" CellSpacing="0" GridLines="None"

                Skin="Outlook" AllowAutomaticUpdates="True" AllowAutomaticInserts="True"

                AllowMultiRowEdit="True">

 

                <ClientSettings ActiveRowIndex="1" AllowKeyboardNavigation="True">

                    <Selecting AllowRowSelect="True" EnableDragToSelectRows="true"

                        UseClientSelectColumnOnly="True" />

                </ClientSettings>

 

                <MasterTableView CommandItemDisplay="None" HeaderStyle-BorderStyle="None"> 

                    <CommandItemSettings ExportToPdfText="Export to PDF"></CommandItemSettings>

 

                    <RowIndicatorColumn FilterControlAltText="Filter RowIndicator column"></RowIndicatorColumn>

 

                    <ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column"></ExpandCollapseColumn>

 

                    <EditFormSettings>

                        <EditColumn FilterControlAltText="Filter EditCommandColumn column"></EditColumn>

                    </EditFormSettings>

 

                    <HeaderStyle BorderStyle="None"></HeaderStyle>                                     

 

                    <Columns>

                        <telerik:GridClientSelectColumn UniqueName="CheckboxSelectColumn" FooterText="CheckBoxSelect footer" />

                        <telerik:GridTemplateColumn HeaderText="Validar" UniqueName="ColumnaValidaParte"

                            FilterControlAltText="Filter column">

                            <ItemTemplate>

                                <asp:CheckBox ID="ColumnaValidar" AutoPostBack="False" OnCheckedChanged="ToggleRowSelection" runat="server" ></asp:CheckBox>

                            </ItemTemplate>

                        </telerik:GridTemplateColumn>

                    </Columns>

 

                    <EditFormSettings>

                        <EditColumn FilterControlAltText="Filter EditCommandColumn column">

                        </EditColumn>

                    </EditFormSettings>

                </MasterTableView>

 

                <FilterMenu EnableImageSprites="False" EnableSelection="True"></FilterMenu>

 

                <HeaderContextMenu CssClass="GridContextMenu GridContextMenu_Default" EnableSelection="True"></HeaderContextMenu>

            </telerik:RadGrid>


 I tried with two kinds of checkbox one of them like Raja's checkbox (in that case ColumnaValidaParte) and another ClientSelect Checkbox (in that case CheckboxSelectColumn).

 The question is: How can I get id of selected rows on server side?

 Thanks in advance for your colaboration.

 Note: I work with Telerik Premium Collection for .NET RadControls for ASP.NET AJAX Q2 2011 on Visual Studio .NET 2010
0
Shinu
Top achievements
Rank 2
answered on 28 Jan 2013, 06:40 AM
Hi,

I suppose you want to access selected values in CheckChanged event. Here is the sample code.
C#:
protected void CheckBox2_CheckedChanged(object sender, EventArgs e)
{
        foreach (GridDataItem item in RadGrid1.SelectedItems)
        {
            string value = item["Uniquename"].Text;
        }
}

Thanks,
Shinu
Tags
Grid
Asked by
Raja Rajeswari Mohan Venkataraman
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
ASTI
Top achievements
Rank 1
Shinu
Top achievements
Rank 2
Share this question
or