Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/264.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Gridview ASP.NET锁定第一列和第一行_C#_Jquery_Css_Asp.net_Gridview - Fatal编程技术网

C# Gridview ASP.NET锁定第一列和第一行

C# Gridview ASP.NET锁定第一列和第一行,c#,jquery,css,asp.net,gridview,C#,Jquery,Css,Asp.net,Gridview,我需要冻结列0,1,同时我想冻结行(不是标题,标题是隐藏的)0,1,2,当用户上下滚动,也从左向右滚动时,这些列和行将是静态的,我尝试了一些jQuery代码,但它没有工作,我在一个堆栈溢出问题中发现了这个CSS示例,我把它作为我的项目。到目前为止,我只使用列来尽快完成这项工作,但是,正如我之前所说的,我还需要锁定行 我有一个gridview ASP.NET C#在一个HTML表中,在“加载页面”事件中,网格会被数据表信息填充。此数据表从SQL数据库获取信息 当事件触发时,我正在网格上应用CSS,

我需要冻结列0,1,同时我想冻结行(不是标题,标题是隐藏的)0,1,2,当用户上下滚动,也从左向右滚动时,这些列和行将是静态的,我尝试了一些jQuery代码,但它没有工作,我在一个堆栈溢出问题中发现了这个CSS示例,我把它作为我的项目。到目前为止,我只使用列来尽快完成这项工作,但是,正如我之前所说的,我还需要锁定行

我有一个gridview ASP.NET C#在一个HTML表中,在“加载页面”事件中,网格会被数据表信息填充。此数据表从SQL数据库获取信息

当事件触发时,我正在网格上应用CSS,所有这些都很好

为了让您了解网格的外观,下面是一个示例:

您无法看到水平滚动条,因为用户选择的年数,但这可能会根据用户的选择而改变

这是我最近使用的CSS:

    .pinned
{
    position:fixed; 
    background-color: #FFFFFF; 
    z-index: 100;


}
.scrolled
{
    position: relative;
    left: 150px; 
    overflow: hidden;
    white-space: nowrap;
    min-width: 50px; 
}
.col1
{
    left: 0px;
    width: 50px;
}
.col2

{
    left: 50px;  
    width: 100px;
}
HTML:

如果你想知道我申请后得到了什么,这是:

看起来:搞砸了!前三排。。。我不知道发生了什么。colspan应用于不同的事件

如果您想知道colspan Rowcreated事件是什么,是:

        protected void COl(object sender, GridViewRowEventArgs e)
    {
        int index = e.Row.RowIndex;
        int i = e.Row.Cells.Count;

        if (i == 4)
        {

            if (index == 0)
            {
                for (int j = 2; j <= (i - 1); j++)
                {
                    //e.Row.Cells[j].CssClass = "GVFixedHeader";
                    e.Row.Cells[j].CssClass = "FILACSS";
                }
                // e.Row.Cells[2].Text = "ACUMULADO DE ENERO - " + NomMes;

                e.Row.Cells[2].ColumnSpan = 2;
                e.Row.Cells.RemoveAt(3);
            }

            if (index == 1)
            {
                for (int j = 2; j <= (i - 1); j++)
                {
                    e.Row.Cells[j].CssClass = "FILACSS";
                }

            }

            if (index == 2)
            {
                for (int j = 2; j <= (i - 1); j++)
                {
                    e.Row.Cells[j].CssClass = "FILACSS";
                }

            }



        }
        if (i == 8)
        {
            if (index == 0)
            {
                for (int j = 2; j <= (i - 1); j++)
                {
                    //e.Row.Cells[j].CssClass = "FILACSS";
                    e.Row.Cells[j].CssClass = "FILACSS";

                }

                //*******************************
                //e.Row.Cells[0].Text = "ACUMULADO DE ENERO - " + NomMes;
                e.Row.Cells[2].ColumnSpan = 6;

                for (int b = 7; b >= 3; b--)
                {
                    e.Row.Cells.RemoveAt(b);
                }


            }

            if (index == 1)
            {
                for (int j = 2; j <= (i - 1); j++)
                {
                    //e.Row.Cells[j].CssClass = "FILACSS";
                    e.Row.Cells[j].CssClass = "FILACSS";
                }

                //******************************
                for (int b = 2; b <= 6; b++)
                {
                    e.Row.Cells[b].ColumnSpan = 2;
                    b++;
                }

                for (int b = 7; b >= 3; b--)
                {
                    e.Row.Cells.RemoveAt(b);
                    b--;
                }


            }

            if (index == 2)
            {
                for (int j = 2; j <= (i - 1); j++)
                {
                    //e.Row.Cells[j].CssClass = "FILACSS";
                    e.Row.Cells[j].CssClass = "FILACSS";
                }

            }
        }
        if (i == 10)
        {

            if (index == 0)
            {
                for (int j = 2; j <= (i - 1); j++)
                {
                    e.Row.Cells[j].CssClass = "FILACSS";
                }

                //*******************************
                //e.Row.Cells[2].Text = "ACUMULADO DE ENERO - " + NomMes;
                e.Row.Cells[2].ColumnSpan = 8;

                for (int b = 9; b >= 3; b--)
                {
                    e.Row.Cells.RemoveAt(b);
                }


            }

            if (index == 1)
            {
                for (int j = 2; j <= (i - 1); j++)
                {
                    e.Row.Cells[j].CssClass = "FILACSS";
                }

                //******************************
                for (int b = 2; b <= 8; b++)
                {
                    e.Row.Cells[b].ColumnSpan = 2;
                    b++;
                }

                for (int b = 9; b >= 3; b--)
                {
                    e.Row.Cells.RemoveAt(b);
                    b--;
                }


            }

            if (index == 2)
            {
                for (int j = 2; j <= (i - 1); j++)
                {
                    e.Row.Cells[j].CssClass = "FILACSS";
                }

            }

        }

        if (i == 12)
        {
            if (index == 0)
            {
                for (int j = 2; j <= (i - 1); j++)
                {
                    e.Row.Cells[j].CssClass = "FILACSS";
                }

                //*******************************
                //e.Row.Cells[2].Text = "ACUMULADO DE ENERO - " + NomMes;
                e.Row.Cells[2].ColumnSpan = 10;

                for (int b = 11; b >= 3; b--)
                {
                    e.Row.Cells.RemoveAt(b);
                }


            }

            if (index == 1)
            {
                for (int j = 2; j <= (i - 1); j++)
                {
                    e.Row.Cells[j].CssClass = "FILACSS";
                }

                //******************************
                for (int b = 2; b <= 10; b++)
                {
                    e.Row.Cells[b].ColumnSpan = 2;
                    b++;
                }

                for (int b = 11; b >= 3; b--)
                {
                    e.Row.Cells.RemoveAt(b);
                    b--;
                }


            }

            if (index == 2)
            {
                for (int j = 2; j <= (i - 1); j++)
                {
                    e.Row.Cells[j].CssClass = "FILACSS";
                }

            }
        }
    }
protectedvoid列(对象发送方,GridViewRowEventArgs e)
{
int index=e.Row.RowIndex;
int i=e.Row.Cells.Count;
如果(i==4)
{
如果(索引==0)
{

对于(int j=2;j我昨晚一直在研究这个问题,我为第0列和第1列找到了一个解决方案,但是我仍然没有冻结第一行(0,1,2)。我处理的这个示例冻结了标题,但正如我前面所说的,我将隐藏标题

这是我正在应用的新代码:

HTML:


我举了以下例子:

        protected void ROWCSS(object sender, GridViewRowEventArgs e)
    {
        int i = e.Row.Cells.Count;
        int index = e.Row.RowIndex;



        if (e.Row.RowType == DataControlRowType.DataRow)
        {

 //THIS IS THE FOR, THAT LOCKS THE COLUMN 0 and 1 ************

            for (int j = 0; j <= (i - 1); j++)
            {

                if (j == 0)
                {
                    e.Row.Cells[j].CssClass = "pinned col1";
                }
                else if (j == 1)
                {
                    e.Row.Cells[j].CssClass = "pinned col2";
                }

                else
                {
                    e.Row.Cells[j].CssClass = "scrolled";
                }

            }

 //********************************


            if (index == 3 || index == 32 || index == 46 || index == 50)
            {
                for (int j = 0; j <= (i - 1); j++)
                {
                    //Si la columna es la 0 o la 1, entonces aplicar formato izquierdo
                    if (j == 0 || j == 1)
                    {
                        e.Row.Cells[j].CssClass = "naranjaCSSLEFT";
                    }
                    //En caso contrario, formato derecho
                    else
                    {
                        e.Row.Cells[j].CssClass = "naranjaCSSRIGHT";
                    }

                }
            }

            else if (index == 4 || index == 15 || index == 29 || index == 33 || index == 41)
            {
                for (int j = 0; j <= (i - 1); j++)
                {
                    //Si la columna es la 0 o la 1, entonces aplicar formato izquierdo
                    if (j == 0 || j == 1)
                    {
                        e.Row.Cells[j].CssClass = "azulCSSLEFT";
                    }
                    //En caso contrario, formato derecho
                    else
                    {
                        e.Row.Cells[j].CssClass = "azulCSSRIGHT";
                    }

                }
            }

            else if (!(index == 0 || index == 1 || index == 2))
            {
                for (int j = 0; j <= (i - 1); j++)
                {
                    //Si la columna es la 0 o la 1, entonces aplicar formato izquierdo
                    if (j == 0 || j == 1)
                    {
                        e.Row.Cells[j].CssClass = "negroCSSLEFT";
                    }
                    //En caso contrario, formato derecho
                    else
                    {
                        e.Row.Cells[j].CssClass = "negroCSSRIGHT";
                    }

                }
            }



        }
    }
                    .naranjaCSSLEFT
            {
            font-weight:bold;
            color:#C65911;
            font-size: 13px;
            text-align:left;
            font-family:tahoma;
            }
            .naranjaCSSRIGHT
            {
            font-weight:bold;
            color:#C65911;
            font-size: 13px;
            text-align:right;
            font-family:tahoma;
            }

            .azulCSSLEFT
            {
            font-weight:bold;
            color:#2F75B5;
            font-size: 13px;
            text-align:left;
            font-family:tahoma;
            }
            .azulCSSRIGHT
            {
            font-weight:bold;
            color:#2F75B5;
            font-size: 13px;
            text-align:right;
            font-family:tahoma;
            }
            .negroCSSLEFT
            {
            font-weight:normal;
            color:#000000;
            font-size: 13px;
            text-align:left;
            font-family:tahoma;
            }
            .negroCSSRIGHT
            {
            font-weight:normal ;
            color:#000000;
            font-size: 13px;
            text-align:right;
            font-family:tahoma;

            }

            .FILACSS
            {
            font-weight:bold ;
            color:#FFFFFF;
            font-size: 13px;
            text-align:center;
            font-family:tahoma;
            background:#2F75B5;
            border:hidden;
            }
        protected void COl(object sender, GridViewRowEventArgs e)
    {
        int index = e.Row.RowIndex;
        int i = e.Row.Cells.Count;

        if (i == 4)
        {

            if (index == 0)
            {
                for (int j = 2; j <= (i - 1); j++)
                {
                    //e.Row.Cells[j].CssClass = "GVFixedHeader";
                    e.Row.Cells[j].CssClass = "FILACSS";
                }
                // e.Row.Cells[2].Text = "ACUMULADO DE ENERO - " + NomMes;

                e.Row.Cells[2].ColumnSpan = 2;
                e.Row.Cells.RemoveAt(3);
            }

            if (index == 1)
            {
                for (int j = 2; j <= (i - 1); j++)
                {
                    e.Row.Cells[j].CssClass = "FILACSS";
                }

            }

            if (index == 2)
            {
                for (int j = 2; j <= (i - 1); j++)
                {
                    e.Row.Cells[j].CssClass = "FILACSS";
                }

            }



        }
        if (i == 8)
        {
            if (index == 0)
            {
                for (int j = 2; j <= (i - 1); j++)
                {
                    //e.Row.Cells[j].CssClass = "FILACSS";
                    e.Row.Cells[j].CssClass = "FILACSS";

                }

                //*******************************
                //e.Row.Cells[0].Text = "ACUMULADO DE ENERO - " + NomMes;
                e.Row.Cells[2].ColumnSpan = 6;

                for (int b = 7; b >= 3; b--)
                {
                    e.Row.Cells.RemoveAt(b);
                }


            }

            if (index == 1)
            {
                for (int j = 2; j <= (i - 1); j++)
                {
                    //e.Row.Cells[j].CssClass = "FILACSS";
                    e.Row.Cells[j].CssClass = "FILACSS";
                }

                //******************************
                for (int b = 2; b <= 6; b++)
                {
                    e.Row.Cells[b].ColumnSpan = 2;
                    b++;
                }

                for (int b = 7; b >= 3; b--)
                {
                    e.Row.Cells.RemoveAt(b);
                    b--;
                }


            }

            if (index == 2)
            {
                for (int j = 2; j <= (i - 1); j++)
                {
                    //e.Row.Cells[j].CssClass = "FILACSS";
                    e.Row.Cells[j].CssClass = "FILACSS";
                }

            }
        }
        if (i == 10)
        {

            if (index == 0)
            {
                for (int j = 2; j <= (i - 1); j++)
                {
                    e.Row.Cells[j].CssClass = "FILACSS";
                }

                //*******************************
                //e.Row.Cells[2].Text = "ACUMULADO DE ENERO - " + NomMes;
                e.Row.Cells[2].ColumnSpan = 8;

                for (int b = 9; b >= 3; b--)
                {
                    e.Row.Cells.RemoveAt(b);
                }


            }

            if (index == 1)
            {
                for (int j = 2; j <= (i - 1); j++)
                {
                    e.Row.Cells[j].CssClass = "FILACSS";
                }

                //******************************
                for (int b = 2; b <= 8; b++)
                {
                    e.Row.Cells[b].ColumnSpan = 2;
                    b++;
                }

                for (int b = 9; b >= 3; b--)
                {
                    e.Row.Cells.RemoveAt(b);
                    b--;
                }


            }

            if (index == 2)
            {
                for (int j = 2; j <= (i - 1); j++)
                {
                    e.Row.Cells[j].CssClass = "FILACSS";
                }

            }

        }

        if (i == 12)
        {
            if (index == 0)
            {
                for (int j = 2; j <= (i - 1); j++)
                {
                    e.Row.Cells[j].CssClass = "FILACSS";
                }

                //*******************************
                //e.Row.Cells[2].Text = "ACUMULADO DE ENERO - " + NomMes;
                e.Row.Cells[2].ColumnSpan = 10;

                for (int b = 11; b >= 3; b--)
                {
                    e.Row.Cells.RemoveAt(b);
                }


            }

            if (index == 1)
            {
                for (int j = 2; j <= (i - 1); j++)
                {
                    e.Row.Cells[j].CssClass = "FILACSS";
                }

                //******************************
                for (int b = 2; b <= 10; b++)
                {
                    e.Row.Cells[b].ColumnSpan = 2;
                    b++;
                }

                for (int b = 11; b >= 3; b--)
                {
                    e.Row.Cells.RemoveAt(b);
                    b--;
                }


            }

            if (index == 2)
            {
                for (int j = 2; j <= (i - 1); j++)
                {
                    e.Row.Cells[j].CssClass = "FILACSS";
                }

            }
        }
    }
                       <div>
                   <asp:GridView ID="cphMain_cphMain_cphMain_GridView2" runat="server" Width="100%" AutoGenerateColumns="true" GridLines="None" 
                       OnRowCreated="COl"   OnRowDataBound="ROWCSS">  
                   <RowStyle HorizontalAlign="Left" VerticalAlign="Middle" Wrap="False" />

                </asp:GridView>
                <script type="text/javascript">
                    $(document).ready(function () {
                        $('#cphMain_cphMain_cphMain_GridView2').gridviewScroll({
                            width: 930,
                            height: 400,
                            freezesize: 2
                        });
                    });
                 </script>
               </div> 
       <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 src="JQuery/GridViewHeader.js"></script>
 //THIS IS THE FOR, THAT LOCKS THE COLUMN 0 and 1 ************

        for (int j = 0; j <= (i - 1); j++)
        {

            if (j == 0)
            {
                e.Row.Cells[j].CssClass = "pinned col1";
            }
            else if (j == 1)
            {
                e.Row.Cells[j].CssClass = "pinned col2";
            }

            else
            {
                e.Row.Cells[j].CssClass = "scrolled";
            }

        }

//********************************
<script src="JQuery/GridViewHeader.js"></script>