How To Select Multiple Rows in Rad Grid.

2 posts, 0 answers
  1. Sairam
    Sairam avatar
    56 posts
    Member since:
    May 2013

    Posted 04 May 2013 Link to this post

    I am New In  Telerik rad control using ,I have requirement in like this,In I have 2 Rad grid's 1 Is outer One Another one inside  "Outer One " Is like this it's have four column  Edit, Delete  And Insert  ,The second rad gird Is like this  It's Inside A  GridTemplatecolumn  of outer grid
    Insert and Edit Operation ,click I want to display the Grid, and when user click  on  Here I want  to Allow user to select Multiple rows But in grid I am Display the  DataValue and Checkbox Dynamically created  .aspx.cs ,I  Am bind to the Inner Grid .When User Mouse  click On particular row I am Don't Want  to Select the row ,Only When User Click's On "Check Box" I want to allow to select the row other wise ,Don't allow to select the rows .


    This code   I am Written.
    Bank.aspx
     <telerik:RadGrid ID="RadGrid1" runat="server" AllowFilteringByColumn="True" OnNeedDataSource="RadGrid1_NeedDataSource"
            AllowSorting="True" PageSize="10" AllowCustomPaging="True" AllowPaging="True"
            OnPageIndexChanged="RadGrid1_PageIndexChanged" OnPageSizeChanged="RadGrid1_PageSizeChanged"
            OnInsertCommand="RadGrid1_InsertCommand" OnUpdateCommand="RadGrid1_UpdateCommand"
            OnItemCreated="RadGrid1_ItemCreated" OnDeleteCommand="RadGrid1_DeleteCommand"
            GridLines="Both" AutoGenerateColumns="False" Skin="Office2007" ShowStatusBar="True"
            CellSpacing="0" CssClass="MainGrid" Width="500px" OnItemDataBound="RadGrid1_ItemDataBound"
            EnableHeaderContextMenu="true">
            <EditItemStyle BackColor="Gray" />
            <GroupingSettings CaseSensitive="false" />
            <MasterTableView CommandItemDisplay="TopAndBottom" AutoGenerateColumns="false" DataKeyNames="id,BankRoutingNumber,BankAccountNumber"
                InsertItemPageIndexAction="ShowItemOnCurrentPage" EditMode="EditForms" GridLines="None"
                TableLayout="Auto" AllowCustomSorting="true" Width="500px">
                <PagerStyle Mode="NextPrevNumericAndAdvanced" />
                <CommandItemStyle CssClass="lnkNormal" />
                <CommandItemSettings ExportToPdfText="Export to PDF"></CommandItemSettings>
                <RowIndicatorColumn Visible="true" FilterControlAltText="Filter RowIndicator column">
                </RowIndicatorColumn>
                <ExpandCollapseColumn Visible="True" FilterControlAltText="Filter ExpandColumn column">
                </ExpandCollapseColumn>
                <ItemStyle ForeColor="#424242" Font-Size="12px" />
                <AlternatingItemStyle Height="10px" BackColor="#EAEAEA" ForeColor="#424242" Font-Size="12px" />
                <HeaderStyle HorizontalAlign="Left" Height="5px" />
                <CommandItemStyle Height="5px" />
                <Columns>
                    <telerik:GridEditCommandColumn ButtonType="ImageButton" FooterText="EditCommand footer"
                        EditImageUrl="images/Edit.gif" UniqueName="id" HeaderStyle-Width="30px" />
                    <telerik:GridTemplateColumn DataField="BankRoutingNumber" HeaderText="Bank Routing Number"
                        SortExpression="BankRoutingNumber" UniqueName="BankRoutingNumber" AutoPostBackOnFilter="true"
                        CurrentFilterFunction="EqualTo" ItemStyle-HorizontalAlign="Left" FilterControlWidth="80px"
                        HeaderStyle-Width="135px" HeaderStyle-BackColor="LightGray" HeaderStyle-Font-Size="12px">
                        <ItemTemplate>
                            <%#Eval("BankRoutingNumber")%>
                        </ItemTemplate>
                        <InsertItemTemplate>
                            <telerik:RadTextBox ID="rtBankRoutingNumber1" runat="server" Width="150px" MaxLength="9"
                                onkeypress="return isNumberKey(event)" OnTextChanged="RadGrid1_TextChanged1"
                                AutoPostBack="true" onclick="shouldConfirm = true;">
                            </telerik:RadTextBox>
                            <asp:RequiredFieldValidator ID="rfvBankRoutingNumber1" runat="server" ErrorMessage=" Bank Routing Number is required"
                                ControlToValidate="rtBankRoutingNumber1" Display="Dynamic" ForeColor="Red"></asp:RequiredFieldValidator>
                        </InsertItemTemplate>
                        <EditItemTemplate>
                            <telerik:RadTextBox ID="rtBankRoutingNumber" runat="server" Text='<%# Eval("BankRoutingNumber") %>'
                                Width="150px" OnTextChanged="RadGrid1_TextChanged" AutoPostBack="true" MaxLength="9"
                                onkeypress="return isNumberKey(event)" onclick="shouldConfirm = true;">
                            </telerik:RadTextBox>
                            <asp:RequiredFieldValidator ID="rfvBankRoutingNumber" runat="server" ErrorMessage="Bank Routing Number is required"
                                ControlToValidate="rtBankRoutingNumber" Display="Dynamic" ForeColor="Red"></asp:RequiredFieldValidator>
                        </EditItemTemplate>
                    </telerik:GridTemplateColumn>
                    <telerik:GridTemplateColumn DataField="BankAccountNumber" SortExpression="BankAccountNumber"
                        HeaderText="Bank Account Number" UniqueName="BankAccountNumber" AutoPostBackOnFilter="true"
                        CurrentFilterFunction="EqualTo" ItemStyle-HorizontalAlign="Left" FilterControlWidth="80px"
                        HeaderStyle-Width="140px" HeaderStyle-BackColor="LightGray" HeaderStyle-Font-Size="12px">
                        <ItemTemplate>
                            <%#Eval("BankAccountNumber")%>
                        </ItemTemplate>
                        <InsertItemTemplate>
                            <telerik:RadTextBox ID="rtBankAccountNumber1" runat="server" MaxLength="16" Width="150px"
                                onkeypress="return isNumberKey(event)" onclick="shouldConfirm = true;">
                            </telerik:RadTextBox>
                            <asp:RequiredFieldValidator ID="rfvMainBankAccountNumber" runat="server" ErrorMessage="Account Number is required"
                                ControlToValidate="rtBankAccountNumber1" Display="Dynamic" ForeColor="Red"></asp:RequiredFieldValidator>
                            <asp:RegularExpressionValidator Display="Dynamic" ControlToValidate="rtBankAccountNumber1"
                                ID="RegularExpressionValidator3" ValidationExpression="^[0-9]{9,16}$" ForeColor="Red"
                                runat="server" ErrorMessage="Minimum 9 and Maximum 16 Numbers Required"></asp:RegularExpressionValidator>
                        </InsertItemTemplate>
                        <EditItemTemplate>
                            <telerik:RadTextBox ID="rtBankAccountNumber" runat="server" ReadOnly="false" MaxLength="16"
                                Text='<%# Eval("BankAccountNumber") %>' Width="150px" onkeypress="return isNumberKey(event)"
                                onclick="shouldConfirm = true;">
                            </telerik:RadTextBox>
                            <asp:RequiredFieldValidator ID="rfveditMainBankAccountNumber" runat="server" ErrorMessage="Account Number is required"
                                ControlToValidate="rtBankAccountNumber" Display="Dynamic" ForeColor="Red"></asp:RequiredFieldValidator>
                            <asp:RegularExpressionValidator Display="Dynamic" ControlToValidate="rtBankAccountNumber"
                                ID="rertBankAccountNumber" ValidationExpression="^[0-9]{9,16}$" ForeColor="Red"
                                runat="server" ErrorMessage="Minimum 9 and Maximum 16 Numbers Required"></asp:RegularExpressionValidator>
                        </EditItemTemplate>
                    </telerik:GridTemplateColumn>
                    <telerik:GridTemplateColumn DataField="BankAccountNumbeVerr" SortExpression="BankAccountNumbeVerr"
                        HeaderText="Confirm Account Number" UniqueName="BankAccountNumberVer" Visible="false"
                        CurrentFilterFunction="EqualTo" AutoPostBackOnFilter="true" ItemStyle-HorizontalAlign="Left"
                        FilterControlWidth="80px" HeaderStyle-Width="80px" HeaderStyle-BackColor="LightGray"
                        HeaderStyle-Font-Size="12px">
                        <ItemTemplate>
                            <%#Eval("BankAccountNumber")%>
                        </ItemTemplate>
                        <InsertItemTemplate>
                            <telerik:RadTextBox ID="rtBankAccountNumberVer" runat="server" ReadOnly="false" MaxLength="16"
                                Width="150px" onclick="shouldConfirm = true;">
                            </telerik:RadTextBox>
                            <asp:RequiredFieldValidator ID="rfvrtBankAccountNumberVer" runat="server" ErrorMessage="Confirm Account Number is required"
                                ControlToValidate="rtBankAccountNumberVer" Display="Dynamic" ForeColor="Red"></asp:RequiredFieldValidator>
                            <asp:CompareValidator ID="CompareValidator1" runat="server" ErrorMessage="Account number not match"
                                ControlToCompare="rtBankAccountNumber1" ControlToValidate="rtBankAccountNumberVer"
                                Display="Dynamic" ForeColor="Red"></asp:CompareValidator>
                        </InsertItemTemplate>
                        <EditItemTemplate>
                            <telerik:RadTextBox ID="rtBankAccountNumberVer1" runat="server" ReadOnly="false"
                                MaxLength="16" Width="150px" Text='<%# Eval("BankAccountNumber") %>' onclick="shouldConfirm = true;">
                            </telerik:RadTextBox>
                            <asp:RequiredFieldValidator ID="rfvrtBankAccountNumberVer" runat="server" ErrorMessage="Confirm Account Number is required"
                                ControlToValidate="rtBankAccountNumberVer1" Display="Dynamic" ForeColor="Red"></asp:RequiredFieldValidator>
                            <asp:CompareValidator ID="CompareValidator" runat="server" ErrorMessage="Account number not match"
                                ControlToCompare="rtBankAccountNumber" ControlToValidate="rtBankAccountNumberVer1"
                                Display="Dynamic" ForeColor="Red"></asp:CompareValidator>
                        </EditItemTemplate>
                    </telerik:GridTemplateColumn>
                    <telerik:GridTemplateColumn DataField="BankName" HeaderText="Bank Name" SortExpression="BankName"
                        UniqueName="BankName" AutoPostBackOnFilter="true" ItemStyle-HorizontalAlign="Left"
                        FilterControlWidth="80px" HeaderStyle-Width="300px" HeaderStyle-BackColor="LightGray"
                        HeaderStyle-Font-Size="12px">
                        <ItemTemplate>
                            <%#Eval("BankName")%>
                        </ItemTemplate>
                        <InsertItemTemplate>
                            <telerik:RadTextBox ID="rtBankName1" runat="server" Width="150px" ReadOnly="false"
                                Enabled="false" onclick="shouldConfirm = true;">
                            </telerik:RadTextBox>
                            <asp:RequiredFieldValidator ID="rfvBankName1" runat="server" ErrorMessage="Bank Name is required"
                                ControlToValidate="rtBankName1" Display="Dynamic" ForeColor="Red"></asp:RequiredFieldValidator>
                        </InsertItemTemplate>
                        <EditItemTemplate>
                            <telerik:RadTextBox ID="rtBankName" runat="server" Text='<%# Eval("BankName") %>'
                                Width="150px" ReadOnly="false" onclick="shouldConfirm = true;" Enabled="false">
                            </telerik:RadTextBox>
                            <asp:RequiredFieldValidator ID="rfvBankName" runat="server" ErrorMessage="Bank Name is required"
                                ControlToValidate="rtBankName" Display="Dynamic" ForeColor="Red"></asp:RequiredFieldValidator>
                        </EditItemTemplate>
                    </telerik:GridTemplateColumn>
                    <telerik:GridTemplateColumn HeaderText="Bank Type" Visible="false" UniqueName="BankType"
                        SortExpression="BankType" HeaderStyle-BackColor="LightGray">
                        <InsertItemTemplate>
                            <telerik:RadGrid ID="RgList" runat="server" AutoGenerateColumns="false" AllowMultiRowSelection="true"
                                ShowHeader="false" Width="148px">
                                <MasterTableView AutoGenerateColumns="false">
                                    <Columns>
                                        <telerik:GridTemplateColumn>
                                            <ItemTemplate>
                                                <%#Eval("CheckList") %></ItemTemplate>
                                        </telerik:GridTemplateColumn>
                                        <telerik:GridClientSelectColumn />
                                    </Columns>
                                </MasterTableView>
                                <ClientSettings>
                                    <Selecting AllowRowSelect="true" />
                                </ClientSettings>
                            </telerik:RadGrid>
                        </InsertItemTemplate>
                        <EditItemTemplate>
                            <telerik:RadGrid ID="RgList1" runat="server" AutoGenerateColumns="false" AllowMultiRowSelection="true"
                                ShowHeader="false" Width="148px">
                                <MasterTableView AutoGenerateColumns="false">
                                    <Columns>
                                        <telerik:GridTemplateColumn>
                                            <ItemTemplate>
                                                <%#Eval("CheckList") %></ItemTemplate>
                                        </telerik:GridTemplateColumn>
                                        <telerik:GridClientSelectColumn />
                                    </Columns>
                                </MasterTableView>
                                <ClientSettings>
                                    <Selecting AllowRowSelect="true" />
                                </ClientSettings>
                            </telerik:RadGrid>
                        </EditItemTemplate>
                    </telerik:GridTemplateColumn>
                    <telerik:GridButtonColumn ButtonType="ImageButton" CommandName="Delete" UniqueName="BankRoutingNumber"
                        ConfirmText="Are you sure you want to delete the selected row?" ConfirmTitle="Bank Details Delete"
                        ImageUrl="images/Delete.gif" ConfirmDialogHeight="100px" ConfirmDialogWidth="300px"
                        ConfirmDialogType="RadWindow" />
                </Columns>
                <EditFormSettings InsertCaption="New bank details" CaptionDataField="BankRoutingNumber"
                    CaptionFormatString="Edit properties of bank details">
                    <FormTableAlternatingItemStyle Wrap="False"></FormTableAlternatingItemStyle>
                    <EditColumn UniqueName="id" ButtonType="ImageButton" CancelImageUrl="images/Cancel.gif"
                        UpdateImageUrl="images/update.gif" InsertImageUrl="images/update.gif">
                    </EditColumn>
                    <FormTableButtonRowStyle HorizontalAlign="Right" CssClass="EditFormButtonRow"></FormTableButtonRowStyle>
                    <FormCaptionStyle CssClass="EditFormHeader"></FormCaptionStyle>
                </EditFormSettings>
            </MasterTableView>
            <ValidationSettings CommandsToValidate="PerformInsert,Update" />
            <ClientSettings AllowColumnsReorder="true" EnableRowHoverStyle="true">
                <Selecting AllowRowSelect="true" />
                <Scrolling AllowScroll="True" UseStaticHeaders="True" SaveScrollPosition="true" ScrollHeight="250px"
                    FrozenColumnsCount="2"></Scrolling>
                <Selecting AllowRowSelect="true" />
                <Resizing AllowColumnResize="true" AllowRowResize="false" ResizeGridOnColumnResize="true"
                    ClipCellContentOnResize="true" EnableRealTimeResize="false" AllowResizeToFit="true" />
                <selecteditemstyle cssclass="rgSelectedRow"></selecteditemstyle>
                <filtermenu enableimagesprites="False">
            </filtermenu>
        </telerik:RadGrid>

    Bank.Aspx.cs
    Dynamically Created  Table With CheckBox
       protected void GetCheckListData(out DataSet local_ds)
        {
            local_ds = null;
            DataTable TblCheckList = new DataTable();
            DataColumn CheckList = new DataColumn("CheckList");
            CheckList.DataType = System.Type.GetType("System.String");
            TblCheckList.Columns.Add(CheckList);
            DataRow RwInvoice = TblCheckList.NewRow();
            DataRow RwDirectDeposit = TblCheckList.NewRow();
            DataRow RwChecks = TblCheckList.NewRow();
            DataRow RwFees = TblCheckList.NewRow();
            DataRow RwTaxes = TblCheckList.NewRow();
            RwInvoice[CheckList] = "Invoices";
            RwDirectDeposit[CheckList] = "Direct Deposits";
            RwChecks[CheckList] = "Checks";
            RwFees[CheckList] = "Fees";
            RwTaxes[CheckList] = "Taxes";
            TblCheckList.Rows.Add(RwInvoice);
            TblCheckList.Rows.Add(RwDirectDeposit);
            TblCheckList.Rows.Add(RwChecks);
            TblCheckList.Rows.Add(RwFees);
            TblCheckList.Rows.Add(RwTaxes);
            DataSet AddDs = new DataSet();
            AddDs.Tables.Add(TblCheckList);
            local_ds = AddDs;
        }

    .dll file method
      protected void GetCheckListData(out DataSet local_ds)
        {
            local_ds = null;
            DataTable TblCheckList = new DataTable();
            DataColumn CheckList = new DataColumn("CheckList");
            CheckList.DataType = System.Type.GetType("System.String");
            TblCheckList.Columns.Add(CheckList);
            DataRow RwInvoice = TblCheckList.NewRow();
            DataRow RwDirectDeposit = TblCheckList.NewRow();
            DataRow RwChecks = TblCheckList.NewRow();
            DataRow RwFees = TblCheckList.NewRow();
            DataRow RwTaxes = TblCheckList.NewRow();
            RwInvoice[CheckList] = "Invoices";
            RwDirectDeposit[CheckList] = "Direct Deposits";
            RwChecks[CheckList] = "Checks";
            RwFees[CheckList] = "Fees";
            RwTaxes[CheckList] = "Taxes";
            TblCheckList.Rows.Add(RwInvoice);
            TblCheckList.Rows.Add(RwDirectDeposit);
            TblCheckList.Rows.Add(RwChecks);
            TblCheckList.Rows.Add(RwFees);
            TblCheckList.Rows.Add(RwTaxes);
            DataSet AddDs = new DataSet();
            AddDs.Tables.Add(TblCheckList);
            local_ds = AddDs;
        }
        #endregion
    protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
        {
            if (e.Item is GridEditableItem && e.Item.IsInEditMode)
            {
                GridEditableItem item = e.Item as GridEditableItem;
                DataSet DsCheckList;
                GetCheckListData(out DsCheckList);
                if (e.Item.OwnerTableView.IsItemInserted)
                {
                   
                    RadGrid radChkList1 = (RadGrid)item.FindControl("RgList");
                    radChkList1.DataSource = DsCheckList;
                    radChkList1.DataBind();
                    DsCheckList.Clear();

                }

    }

    Please Give Me the replay As Much as Possible and send  replay to mail.


  2. Viktor Tachev
    Admin
    Viktor Tachev avatar
    1488 posts

    Posted 07 May 2013 Link to this post

    Hello Sairam,

    I see that you have submitted two tickets for this issue. You could see the answer in your other forum thread here.

    Please submit single ticket for a query. This will allow us to answer your query faster and provide you better quality service.

    All the best,
    Victor
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top