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

[Solved] how to disable specific row selection in rad grid based on specific column value.

7 Answers 2003 Views
Grid
This is a migrated thread and some comments may be shown as answers.
dotnet
Top achievements
Rank 1
dotnet asked on 01 Aug 2010, 09:08 PM
Hi

Please let me know how to disable specific row selection in rad grid based on specific column value with multirowselection using clientselectcolumn .

7 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 02 Aug 2010, 05:45 AM
Hello,


You can easily achieve this by attaching 'OnRowSelecting' client event and check for the column value. Now cancel the event using "eventArgs.set_cancel(true)" method based on condition.

The following link explains how to get the cell value for selected rows from client side.
Getting cell values for selected rows client side


-Shinu.
0
dotnet
Top achievements
Rank 1
answered on 02 Aug 2010, 11:08 AM

Hi Shinu,

Thanks for the suggestion. Basically my requirement is:based on selection of one row and it's one of the column value ,I want to disable the some of the other row selection based on the same column value.

0
Tsvetoslav
Telerik team
answered on 05 Aug 2010, 09:58 AM
Hi there,

If the column values is in a different row thant the one currently being selected, you can retrieve that row from the get_dataItems() collection, get the cell values as Shinu has pointed out and cancel the selecting event for the current row ( args.set-cancel(true) ).

Regards,
Tsvetoslav
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
prat
Top achievements
Rank 1
answered on 27 Sep 2011, 06:24 AM
I have a checkbox in the itemtemplate of a radgrid.
I want to disable the row on which the checkbox was checked.
All my efforts ended up failing.
Is there a solution?
0
Shinu
Top achievements
Rank 2
answered on 27 Sep 2011, 07:02 AM
Hello Prat,

You can achieve this by attaching onclient client event to the CheckBox. Here is a sample code to achieve the same.

Aspx:
<telerik:GridTemplateColumn HeaderText="ToggleRowSelection" UniqueName="ToggleRowSelection">
        <ItemTemplate>
              <asp:CheckBox ID="CheckBox1" AutoPostBack="True" runat="server">
               </asp:CheckBox>
        </ItemTemplate>
</telerik:GridTemplateColumn>
C#:
protected void rg1_ItemCreated(object sender, GridItemEventArgs e)
   {
       if (e.Item is GridDataItem)
       {
           GridDataItem item = (GridDataItem)e.Item;
           CheckBox chk1 = (CheckBox)item.FindControl("CheckBox1");
           chk1.Attributes.Add("onclick", "onClick(" +item.ItemIndex + ");");//Passing the Index
       }
   }

Javascript:
function onClick(index)
 {
       var RadGrid1 = $find('<%=rg1.ClientID %>');
       var masterTableView = RadGrid1.get_masterTableView();
       var row = masterTableView.get_dataItems()[index];
       row.get_element().disabled = true;
   }

Another approach is from server side by attaching OnCheckedChangeEvent. Here is the sample code.
 
protected void chk_CheckedChanged(object sender, EventArgs e)
    {
        CheckBox chk = sender as CheckBox;
        GridDataItem item = (GridDataItem)chk.NamingContainer;
        if (chk.Checked)
        {
            item.Enabled = false;
        
    }

Thanks,
Shinu.
0
prat
Top achievements
Rank 1
answered on 06 Oct 2011, 04:29 AM
Ineed to copy the text entered on textbox1 to the radtextboxes inside the radgrid thru js.

Textbox1.Attributes.Add("onblur", " cpy(" + Radtextbox1.ClientID+ "," + Textbox1.ClientID + ")");

i use the above expression to pass the client id of the Radtextbox inside the radgrid to evaluate the javascript code.
But this obviously passes only the client id of the last occurrence of Radtextbox1 which is inside the radgrid.
But i need to pass all the client ids of the Radtextboxs1 inside the radgrid  to the javascript code.

Im not sure how to pass the client ids of  textboxes that appear in each row inside the radgrid.
need this real soon. any suggestions anyone?
0
Princy
Top achievements
Rank 2
answered on 09 May 2013, 12:05 PM
Hi prat,

Please have a look at the following code I tried which works fine at my end.

ASPX:
<div>
    <telerik:RadGrid ID="RadGrid1" AllowMultiRowSelection="true" runat="server" DataSourceID="SqlDataSource2"
        AutoGenerateEditColumn="true" AutoGenerateColumns="false" AllowSorting="true"
        ShowHeader="true" AllowFilteringByColumn="true" AllowPaging="true" OnItemCreated="RadGrid1_ItemCreated">
        <MasterTableView CommandItemDisplay="Top" TableLayout="Fixed" DataKeyNames="OrderID"
            ClientDataKeyNames="OrderID">
            <PagerStyle Mode="NextPrevAndNumeric" AlwaysVisible="true" />
            <Columns>
                <telerik:GridTemplateColumn>
                    <ItemTemplate>
                        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
                        <telerik:RadTextBox ID="RadTextBox1" runat="server">
                        </telerik:RadTextBox>
                    </ItemTemplate>
                </telerik:GridTemplateColumn>
            </Columns>
        </MasterTableView>
    </telerik:RadGrid>
</div>
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
    SelectCommand="select top 20 * from [Orders]"></asp:SqlDataSource>

C#:
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
{
    if (e.Item is GridDataItem)
    {
        GridDataItem item = (GridDataItem)e.Item;
        RadTextBox Radtextbox1 = (RadTextBox)item.FindControl("RadTextBox1");
        TextBox Textbox1 = (TextBox)item.FindControl("TextBox1");
        Textbox1.Attributes.Add("onblur", " cpy(" + Radtextbox1.ClientID + "," + Textbox1.ClientID + ")");
    }
}

Thanks,
Princy.
Tags
Grid
Asked by
dotnet
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
dotnet
Top achievements
Rank 1
Tsvetoslav
Telerik team
prat
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Share this question
or