c# - 关闭分页的更简单方法

标签 c# asp.net javascript visual-studio gridview

我想取消我的 gridview 的分页。我通过重定向在 javascript 中执行此操作。我将在下面解释。但我宁愿取消分页,只在更新面板中重新加载我的 Gridview。那怎么办?

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    If Request.Params("R") = "1" Then
        GridView1.AllowPaging = False
    End If
End Sub


function Paging(remove) {
    var txt = $get('<%=TextBox1.ClientID%>');
    var query = window.location.search.substring(1);
    //alert (query);
    window.location = url + 'R=' + remove ;
    txt.value = txt.value;
}

Dim bttnrempag As New Button
    bttnrempag.ID = "bttnrempag"
    bttnrempag.Text = "      Paging"
    bttnrempag.CssClass = "bttnMinEG"
    bttnrempag.ValidationGroup = "alone"
    bttnrempag.Attributes.Add("onclick", "Paging('1')")

    Dim bttnallowpag As New Button
    bttnallowpag.ID = "bttnallowpag"
    bttnallowpag.Text = "      Paging"
    bttnallowpag.ValidationGroup = "alone"
    bttnallowpag.CssClass = "bttnAddEG"
    bttnallowpag.Attributes.Add("onclick", "Paging('0')")
//this is where i add the buttons to my Gridview
    cell.Controls.Add(bttnrempag) '36
    cell.Controls.Add(bttnallowpag)



<asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <ContentTemplate >
        <asp:GridView ID="GridView1" runat="server" AllowPaging="True" 
            AutoGenerateColumns="False" BackColor="White" BorderColor="#E7E7FF" 
            BorderStyle="None" BorderWidth="1px" CellPadding="3" 
            DataSourceID="SqlDataSource1" Font-Names="Comic Sans MS" Font-Size="XX-Small"

            Font-Bold="True" PageSize="15" >
            <RowStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" />

            <Columns>
                <asp:BoundField DataField="scan" HeaderText="Scan" SortExpression="scan" />
                <asp:BoundField DataField="ScanType" HeaderText="ScanType" ReadOnly="True" 
                    SortExpression="ScanType" />
                <asp:TemplateField HeaderText="Item Desc."></asp:TemplateField>
                <asp:BoundField />
                <asp:BoundField />
                <asp:BoundField />
                <asp:BoundField />
                <asp:BoundField  />
                <asp:BoundField  />
                <asp:BoundField  />
            </Columns>
            <FooterStyle BackColor="#B5C7DE" ForeColor="#4A3C8C" />
            <PagerStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" HorizontalAlign="Right" />
            <EmptyDataTemplate>
            <head>
                <meta http-equiv="refresh" content="5;URL=/Corporate_newpo/ReceivingLog.aspx?">
            </head>
                <script type="text/javascript" >
                    var count = 6;
                    var counter = setInterval("timer()", 1000); //1000 will  run it every 1 second

                    function timer() {
                        count = count - 1;
                        if (count <= 0) {
                            clearInterval(counter);
                            //counter ended, do something here
                            return;
                        }
                        $get("timer").innerHTML = "The Table will Reload in " + count + " secs";
                    }
                </script>
                <asp:Label ID="Label1" runat="server" Font-Bold="True" Font-Size="Large" 
                    ForeColor="#993333" Text="No Data was Found for the Selected Filter"></asp:Label><br /><br />
               <span id="timer" style="font-size:medium;color:blue"></span>
            </EmptyDataTemplate>
            <SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="#F7F7F7" />
            <HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#F7F7F7" />
            <AlternatingRowStyle BackColor="#F7F7F7" />

            </asp:GridView>
        </ContentTemplate> 
    </asp:UpdatePanel>

当然,我在网格中有数据。我只是不在这里展示它。 我怎样才能关闭分页,而不必像我在 javascript 中使用 R 那样使用变量重定向?

最佳答案

这是用于关闭 GridView 控件分页的javasscript

  // get datagrid by rendered table name
  var myGridView = document.getElementById('<%= grdvCategoryList.ClientID % >');

   var intNumberOfRows = myGridView.rows.length;
   myGridView.rows[intNumberOfRows-1].style.visibility='hidden';
   myGridView.rows[intNumberOfRows-1].style.display='none';
   return false;

这将隐藏 GridView 控件的最后一行。希望对您有所帮助。

关于c# - 关闭分页的更简单方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1429623/

相关文章:

c# - 在 C# 中将列表转换为 xml

c# - 是否可以将 Linqpad 与存储库和工作单元模式一起使用?

c# - 确认消息框

javascript - 仅当字符串后面没有左方括号或点运算符时才替换字符串,即 "["或 "."

javascript - 调色板中的 MUI 自定义命名选项 - 类型 'primary' 上不存在属性 'TypeBackground'

javascript - 等到js脚本加载到页面上

c# - 带有 DateTimeOffset 的 OData 函数?范围

asp.net - ELMAH 日志如何按类型忽略错误

asp.net - 移动设备 Javascript/CSS 支持。外面有什么?

c# - 如何在 C# 中使用随机数?