Cancel SelectedIndexChanged event server-side

2 posts, 1 answers
  1. Jeremy
    Jeremy avatar
    96 posts
    Member since:
    Mar 2010

    Posted 30 May 2011 Link to this post


    Is there any way to cancel a user selecting another row in a radgrid with server-side validation? I want to allow the user to select a row in the grid, but only if some other textboxes are valid.
    <asp:TextBox ID="txtDummy" runat="server" />

    telerik:RadGrid ID="rgProjects" runat="server"
       <ClientSettings Selecting-AllowRowSelect="true" EnablePostBackOnRowClick="true">
          <Scrolling AllowScroll="true" SaveScrollPosition="true" />
    Code behind:
    protected void rgProjects_SelectedIndexChanged(object sender, EventArgs e)
       Boolean result = CheckProjectChanges(txtDummy.Text);
       if (result == true)
          //continue with stuff - easy
          //cancel row select! how??
  2. Answer
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 30 May 2011 Link to this post

    Hello Jeremy,

    Try the following code snippet to achieve your scenario.

    protected void RadGrid1_SelectedIndexChanged(object sender, EventArgs e)
            var dataItem = RadGrid1.SelectedItems[0] as GridDataItem;//accessing selected row
            dataItem.Selected = false;

Back to Top