当我尝试冻结前两列时GridView有错误

时间:2015-04-27 14:29:51

标签: c# asp.net gridview scroll

我正在使用一个名为GridViewScroll的工具来完成http://gridviewscroll.aspcity.idv.tw/Demo.aspx#Freeze任务。我正在关注示例中显示的所有内容:

他们在示例中使用AdventureWorks数据库,所以我下载了该数据库并将其附加到我的sql server。

My .aspx code
<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" MaintainScrollPositionOnPostback="true" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <link href="StyleSheet.css" rel="stylesheet" type="text/css" />

    <title></title>
</head>
<body>
    <form id="form1" runat="server">

           <div style="overflow-x:scroll;width:1600px;">
           <input id="scrollPos" runat="server" type="hidden" value="0" /> 
          <asp:GridView ID="GridV1" runat="server" Width="100%" 
    AutoGenerateColumns="False" GridLines="None" AllowPaging="True" AllowSorting="True" 
                   DataKeyNames="ProductID" DataSourceID="SqlDataSource1"> 
    <Columns> 
        <asp:BoundField HeaderText="ProductID" DataField="ProductID" 
            ItemStyle-BackColor="#EFEFEF" InsertVisible="False" ReadOnly="True" 
            SortExpression="ProductID" > 
        <HeaderStyle CssClass="GridviewScrollHeader" />
        <ItemStyle CssClass="GridviewScrollItem" />
        </asp:BoundField>
        <asp:BoundField HeaderText="Name" DataField="Name" 
            ItemStyle-BackColor="#EFEFEF" SortExpression="Name" > 
        <HeaderStyle CssClass="GridviewScrollHeader" />
        <ItemStyle CssClass="GridviewScrollItem" />
        </asp:BoundField>
        <asp:BoundField HeaderText="ProductNumber" DataField="ProductNumber" 
            SortExpression="ProductNumber" /> 
        <asp:CheckBoxField DataField="MakeFlag" HeaderText="MakeFlag" 
            SortExpression="MakeFlag" />
        <asp:CheckBoxField DataField="FinishedGoodsFlag" HeaderText="FinishedGoodsFlag" 
            SortExpression="FinishedGoodsFlag" />
        <asp:BoundField HeaderText="Color" DataField="Color" SortExpression="Color" /> 
        <asp:BoundField HeaderText="SafetyStockLevel" DataField="SafetyStockLevel" 
            SortExpression="SafetyStockLevel" /> 
        <asp:BoundField HeaderText="ReorderPoint" DataField="ReorderPoint" 
            SortExpression="ReorderPoint" /> 
        <asp:BoundField HeaderText="StandardCost" DataField="StandardCost" 
            SortExpression="StandardCost" /> 
        <asp:BoundField HeaderText="ListPrice" DataField="ListPrice" 
            SortExpression="ListPrice" /> 
        <asp:BoundField HeaderText="Size" DataField="Size" SortExpression="Size" /> 
        <asp:BoundField DataField="SizeUnitMeasureCode" 
            HeaderText="SizeUnitMeasureCode" SortExpression="SizeUnitMeasureCode" />
        <asp:BoundField DataField="WeightUnitMeasureCode" 
            HeaderText="WeightUnitMeasureCode" SortExpression="WeightUnitMeasureCode" />
        <asp:BoundField DataField="Weight" HeaderText="Weight" 
            SortExpression="Weight" />
        <asp:BoundField DataField="DaysToManufacture" HeaderText="DaysToManufacture" 
            SortExpression="DaysToManufacture" />
        <asp:BoundField DataField="ProductLine" HeaderText="ProductLine" 
            SortExpression="ProductLine" />
        <asp:BoundField DataField="Class" HeaderText="Class" SortExpression="Class" />
        <asp:BoundField DataField="Style" HeaderText="Style" SortExpression="Style" />
        <asp:BoundField DataField="ProductSubcategoryID" 
            HeaderText="ProductSubcategoryID" SortExpression="ProductSubcategoryID" />
        <asp:BoundField DataField="ProductModelID" HeaderText="ProductModelID" 
            SortExpression="ProductModelID" />
        <asp:BoundField DataField="SellStartDate" HeaderText="SellStartDate" 
            SortExpression="SellStartDate" />
        <asp:BoundField DataField="SellEndDate" HeaderText="SellEndDate" 
            SortExpression="SellEndDate" />
        <asp:BoundField DataField="DiscontinuedDate" HeaderText="DiscontinuedDate" 
            SortExpression="DiscontinuedDate" />
        <asp:BoundField DataField="rowguid" HeaderText="rowguid" 
            SortExpression="rowguid" />
        <asp:BoundField DataField="ModifiedDate" HeaderText="ModifiedDate" 
            SortExpression="ModifiedDate" />
    </Columns> 
    <HeaderStyle CssClass="GridviewScrollHeader" /> 
    <RowStyle CssClass="GridviewScrollItem" /> 
    <PagerStyle CssClass="GridviewScrollPager" /> 
</asp:GridView> 

               <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
                   ConnectionString="<%$ ConnectionStrings:AdventureWorks2008ConnectionString %>" 
                   SelectCommand="SELECT TOP 30 * FROM [AdventureWorks2008].[Production].[Product] WHERE DaysToManufacture &gt; 1">
               </asp:SqlDataSource>

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script> 
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.1/jquery-ui.min.js"></script> 
<script type="text/javascript" src="../Scripts/gridviewScroll.min.js"></script> 
<script type="text/javascript">
    $(document).ready(function() {
        gridviewScroll();
    });

    function gridviewScroll() {
        $('#<%=GridV1.ClientID%>').gridviewScroll({
            width: 660,
            height: 200,
            freezesize: 2
        });
    } 
</script>


    </div>

    </form>
</body>
</html>

我在浏览器中运行时遇到以下错误 enter image description here

我做了一些研究,其中一个用户说,如果用户控件与函数相同而不是发生错误。所以我甚至将GridView1的名称更改为GridV1,但错误仍然存​​在

所以当我在错误上单击否时,一切看起来都很好,但前两列不会冻结

enter image description here

gridviewscroll.min.js

enter image description here

将非常感谢任何帮助

2 个答案:

答案 0 :(得分:1)

更新后,很明显路径不正确,应该是

<script type="text/javascript" src="gridviewScroll.min.js"></script>

答案 1 :(得分:0)

感谢@Andrei,我不得不改变

<script type="text/javascript" src="../Scripts/gridviewScroll.min.js"></script>

<script src="gridviewScroll.min.js" type="text/javascript"></script>

因为我将gridviewscroll.min.js放入我的解决方案

enter image description here

解决了我的问题:

enter image description here