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

    Hi

    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.
    eg:
    Markup:
    <asp:TextBox ID="txtDummy" runat="server" />

    <
    telerik:RadGrid ID="rgProjects" runat="server"
          OnNeedDataSource="rgProjects_NeedDataSource"
          OnSelectedIndexChanged="rgProjects_SelectedIndexChanged">
       <ClientSettings Selecting-AllowRowSelect="true" EnablePostBackOnRowClick="true">
          <Scrolling AllowScroll="true" SaveScrollPosition="true" />
       </ClientSettings>
    </telerik:RadGrid>
    Code behind:
    protected void rgProjects_SelectedIndexChanged(object sender, EventArgs e)
    {
       Boolean result = CheckProjectChanges(txtDummy.Text);
       if (result == true)
          //continue with stuff - easy
       else
          //cancel row select! how??
    }
  2. Answer
    Princy
    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.

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

    Thanks,
    Princy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top