在单击按钮事件后,DataTable无法重新显示Gridview [英] DataTable not rendring Gridview after button click event

查看:90
本文介绍了在单击按钮事件后,DataTable无法重新显示Gridview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的页面上,当我的页面正在创建时,一切工作正常,但是当我单击按钮以显示选定的行时,我的网格视图没有呈现为数据表,而我需要做些什么来解决此问题或我正在做的事情

in my page when my page is creating everything is working fine but when i am clicking on button to show the selected row then my grid view is not rendering as a datatables what i need to do to fix this or what i am doing wrong?

我的脚本

<script type="text/javascript">
        $(function () {
            $('[id*=gvTest]').prepend($("<thead></thead>").append($(this).find("tr:first"))).DataTable({
                "responsive": true,
                "sPaginationType": "full_numbers",


            });
        });
        $(document).ready(function () {

            var table = $('#gvTest').DataTable();
            $('#gvTest tbody').on( 'click', 'tr', function () {
            $(this).toggleClass('selected');
            });


            $('#btnRead').click(function () {
           var ids = $.map(table.rows('.selected').data(), function (item) {
               return item[0]
                 });               
            });

    } );
    </script>

我的网格

<asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager>
   <asp:UpdatePanel ID="updatePanel" runat="server">
     <ContentTemplate>

     <asp:GridView  ID="gvTest" Width="100%" runat="server"  AutoGenerateColumns="False" >
      <Columns>
           <asp:BoundField  DataField="PatientID"  HeaderText="Patient ID" >
           </asp:BoundField>
           <asp:BoundField  DataField="PatientName"  HeaderText="PatientName" >
           </asp:BoundField>
           <asp:BoundField  DataField="Age"  HeaderText="Age" >
           </asp:BoundField>
           <asp:BoundField  HeaderText="Sex" DataField="Sex"  >
           </asp:BoundField>
           <asp:BoundField  HeaderText="Mod" DataField="Modality"  >                                 
      </Columns>
    </asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>

创建我的页面时

< a href = https://i.stack.imgur.com/aoHls.png rel = nofollow noreferrer>

一切正常

但是当我单击按钮时然后

But when I click a button then

我现在需要做什么解决这个问题?

What do I need to do now to fix this problem ?

推荐答案


使用了许多其他代码后,我没有得到适当的解决方案,所以我使用了

after using a lots of others code i did'nt get a proper solution so i used this on my page load and its working fine



gvTest.UseAccessibleHeader = true;
//adds <thead> and <tbody> elements
gvTest.HeaderRow.TableSection =
TableRowSection.TableHeader;

这篇关于在单击按钮事件后,DataTable无法重新显示Gridview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆