我有一个 Gridview,它放置了两个用于选择和删除特定行的图像图标。网格绑定到 jquery 数据表,但是当我选择图像来选择行时,默认行为是强制回发,这会导致网格松动数据表设置。
知道如何在单击任一按钮时保留数据表吗?
<asp:GridView ID="grdMessageDups" runat="server" DataSourceID="sourceDuplicates"
AutoGenerateColumns="false">
<Columns>
<asp:CommandField ShowSelectButton="true" ButtonType="Image"
SelectImageUrl="~/images/icn_alert_success.png"/>
<asp:ButtonField ButtonType="Image"
ImageUrl="~/images/icn_alert_error.png" />
<asp:BoundField DataField="MsgDateDetailDuplicatesID" Visible="false" />
<asp:BoundField DataField="1" HeaderText="Heading 1" />
<asp:BoundField DataField="2" HeaderText="Heading 2" />
<asp:BoundField DataField="3" HeaderText="Heading 3" />
</Columns>
</asp:GridView>
然后 DataTable JQuery 的东西是:
var oTable = $('#grdMessageDetail').dataTable({
"aLengthMenu": [[10, 25, 50, 100, -1], [10, 25, 50, 100, "ALL"]],
'asStripClasses': null,
"iDisplayLength": 10,
"bJQueryUI": true,
"bFilter": true,
"bAutoWidth": false,
"bProcessing": true,
"bServerSide": false,
"sDom": 'RC<"H"lfr>t<"F"ip>',
//Scrolling .......
"sScrollY": "250px",
"sScrollX": "100%",
"sScrollXInner": "100%",
"bScrollCollapse": true,
});
后面代码中的代码是:
public static void MakeAccessible(GridView grid)
{
if (grid.Rows.Count <= 0) return;
grid.UseAccessibleHeader = true;
grid.HeaderRow.TableSection = TableRowSection.TableHeader;
if (grid.ShowFooter)
grid.FooterRow.TableSection = TableRowSection.TableFooter;
}
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
MakeAccessible(grdMessageDups);
}