Domanda

I have a Control created which contains a Panel with a RadGrid (DataGrid) and a RadButton (myButton). When I click on the Button, the RadGrid will be disabled or enabled:

myButton.Click += (sender, args) => {
    if (!this.DataGrid.Enabled) {
        this.DataGrid.Enabled = true;
        this.DataGrid.ClientSettings.EnablePostBackOnRowClick = true;
        this.DataGrid.ClientSettings.Resizing.AllowColumnResize = true;
        this.DataGrid.ClientSettings.Selecting.AllowRowSelect = true;
        this.DataGrid.ClientSettings.AllowKeyboardNavigation = true;
    } else {
        this.DataGrid.Enabled = false;
        this.DataGrid.ClientSettings.EnablePostBackOnRowClick = false;
        this.DataGrid.ClientSettings.Resizing.AllowColumnResize = false;
        this.DataGrid.ClientSettings.Selecting.AllowRowSelect = false;
        this.DataGrid.ClientSettings.AllowKeyboardNavigation = false;
    }
    this.DataGrid.Rebind();
}

Disabling is working fine. But when I click a second time, I will get an Exception:

[GridException: Please set ClientSettings.Selecting.AllowRowSelect to "True" to start using GridClientSelectColumn.]

The RadGrid contains a GridClientSelectColumn.

Can anyone please help me, what I can do to prevent this exception? - The exception is occuring before the EventHandler of the myButton will called on the second click.

When I remove the GridClientSelectColumn it is working without Exception.

È stato utile?

Soluzione

This occurs when you have a GridClientSelectColumn. By default a RadGrid fires server side events when a row is clicked, so it has to know that you want the rows to be selected on the client side instead.

The client settings parameters look like this:

<ClientSettings>
  <Selecting AllowRowSelect="True"></Selecting>
</ClientSettings>

They fit in the XML at the root of the declaration of the RadGrid. I've put them before the columns for readability, but they can come after as well.

Notice the <ClientSettings> and the <telerik:GridClientSelectColumn...

<telerik:RadGrid ID="mygrid" 
                 runat="server" AutoGenerateColumns="false" 
                 AllowSorting="true"
                 OnNeedDataSource="mygrid_NeedDataSource"
                 AllowFilteringByColumn="False">
  <ClientSettings>
    <Selecting AllowRowSelect="True"></Selecting>
  </ClientSettings>
  <MasterTableView DataKeyNames="myColumn" Name="Header">
    <Columns>
      <telerik:GridClientSelectColumn ItemStyle-Width="25px" />
      <telerik:GridBoundColumn DataField="myColumn" HeaderText="My Column" />
    </Columns>
  </MasterTableView>
</telerik:RadGrid>

Or, as you have discovered, you can remove the GridClientSelectColumn and fix the error that way.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top