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

a 夏天 提交于 2019-12-12 04:31:55

问题


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


回答1:


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



来源:https://stackoverflow.com/questions/40514338/checking-if-a-aspxgridview-master-detail-has-any-row-checked-in-client-side

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!