popiandro popiandro - 28 days ago 22
Javascript Question

Checking if a aspxgridview Master-Detail has any row checked in Client Side

I need to check if there is any row checked in a Master-Detail AspxGridView.

With the master I can use

grid.GetSelectedRowCount()>0


But how can I check it with the detail rows using JS?

Thanks in advance

Answer

to accomplish this you need to assign a unique ClientInstanceName to each detail grid and then access that particular detail grid on client side using the assigned ClientInstanceName, which in turn should include the master's grid row ID part, ie detailGrid_1 for the first row, detailGrid_2 for the second and so on.

To assign the ClientInstanceName to each detail grid you need to add a custom Page_Init handler to the detail grid as the set ClientInstanceName in that handler in codebehind.

So, the web definition may look like:

<dx:ASPxGridView ID="masterGrid" runat="server" ClientInstanceName="masterGrid">
...
<Templates>
   <DetailRow>
      <dx:ASPxGridView ID="detailGrid" runat="server" OnInit="detailGrid_OnInit">
         ...
      </dx:ASPxGridView>
   </DetailRow>
</Templates>
...
</dx:ASPxGridView>

Then in codebehind:

protected void detailGrid_OnInit(object sender, EventArgs e) {
    ASPxGridView detailGridView = (ASPxGridView)sender;
    GridViewDetailRowTemplateContainer templateContainer =
                   (GridViewDetailRowTemplateContainer)detailGridView.NamingContainer;
    detailGridView.ClientInstanceName = string.Format("detailGrid_{0}",
                                             templateContainer.VisibleIndex);
}

Then on client side in your event handler (you didn't mention upon which event you were trying to check if detail grid has some rows selected) you need to obtain the master grid's row ID and construct a client instance name for your detail grid manually, e.g.:

eval('detailGrid_' + master_grids_row_id).

or you may pass it in a ready-made form to JS even handler like the article below suggests.

Once you have the correct detailGrid Client instance name you can call the following JS method:

detailGrid_XX.GetSelectedKeysOnPage();

See this DX support article for some code samples: https://www.devexpress.com/Support/Center/Question/Details/Q450479

HTH