Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/259.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行_C#_Asp.net_Gridview_Lightbox - Fatal编程技术网

C# 如何隐藏随机生成的gridview行

C# 如何隐藏随机生成的gridview行,c#,asp.net,gridview,lightbox,C#,Asp.net,Gridview,Lightbox,嗨,编码器,我有一个gridview,其中的数据来自数据库。。现在,所有行的id都是相同的,我希望它只显示gridview的第一行,隐藏其余的行,但不显示它们的值,我只是想隐藏它们。我想要它们的价值,因为上面有一个灯箱 这是我的代码: <asp:GridView ID="GridView1" runat="server" CellPadding="4" ForeColor="#333333" GridLines="None" AutoGenerateColumns="Fal

嗨,编码器,我有一个gridview,其中的数据来自数据库。。现在,所有行的id都是相同的,我希望它只显示gridview的第一行,隐藏其余的行,但不显示它们的值,我只是想隐藏它们。我想要它们的价值,因为上面有一个灯箱

这是我的代码:

<asp:GridView ID="GridView1" runat="server" CellPadding="4" ForeColor="#333333" GridLines="None"
        AutoGenerateColumns="False" PageSize="1" PersistedSelection="true" 
    DatakeyNames="pptId,Priority">
        <Columns>

            <asp:TemplateField HeaderText="pptId" Visible="false">
                <ItemTemplate>
                    <asp:Label ID="lblpptId" runat="server" Text='<%# Bind("pptId") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>    
          <asp:TemplateField HeaderText="Priority" Visible="false">
                <ItemTemplate>
                    <asp:Label ID="lblPriority" runat="server" Text='<%# Bind("Priority") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField> 
            <asp:TemplateField HeaderText="View PPT">
                <ItemTemplate>
                    <a id="imageLink" href='<%# Eval("Imageurl") %>' title='<%#Eval("Description") %>'
                        rel="lightbox[Brussels]" runat="server">Start PPT</a>
                </ItemTemplate>
            </asp:TemplateField>                
        </Columns>
        <AlternatingRowStyle BackColor="White" />
        <EditRowStyle BackColor="#2461BF" />
        <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
        <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
        <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
        <RowStyle BackColor="#EFF3FB" />
        <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
        <SortedAscendingCellStyle BackColor="#F5F7FB" />
        <SortedAscendingHeaderStyle BackColor="#6D95E1" />
        <SortedDescendingCellStyle BackColor="#E9EBEF" />
        <SortedDescendingHeaderStyle BackColor="#4870BE" />
         </asp:GridView>
在上面的代码中,pptId对于每一行都是相同的,我的图像显示在我的gridview中,我想要的是只显示第一个图像,隐藏其他图像的其余部分,但不隐藏它们的值


如何做到这一点……提前谢谢

我想这正是您想要的:

for(int i = 1; i < GridView1.Rows.Count; i++)
{
    GridView1.Rows[i].Visible = false;
}
for(int i=1;i

在代码隐藏中将数据源绑定到GridView1后使用它。

你不能用css来完成吗

table tr:nth-child(n + 3) {
    display: none;
}
下面是第n个子css选择器的说明:

我在这里的另一个回答中也解释了这一点:

您可能需要在生成的表上使用一个类或静态id,以便可以将该表单独列出,但仍然

编辑以下评论:

尝试向gridview添加一个css类,然后像这样添加上面的css:

<!DOCTYPE html>
<html>
<head>
    <style type="text/css">
        table.Grid tr:nth-child(n + 3) {
            display: none;
        }
    </style>
</head>
<body>
    <form runat="server">
    <asp:GridView runat="server" CssClass="Grid">
        <%--Your templates here--%>
    </asp:GridView>
    </form>
</body>
</html>

+选择器是相邻的同级选择器。因此,选择器
tr+tr
选择直接跟随另一个tr元素的任何tr。有关进一步的示例,请参见:(特别是标题为“相邻兄弟组合器”的部分)

所以你只想显示第一行而不删除其他行?是的,我不想删除它们,我只想隐藏它们pptId对于每一行是相同的,但是imageurl和优先级是不同的。。。就像你可以说1个ppt有5个不同优先级的图像,所以我显示第一个ppt的图像,但在gridview中,我只显示第一个ppt的图像,隐藏其余的ppt,这样我就有了它们的价值,这样我的灯箱就可以工作了,我不确定我是否得到了它。。。如果priotity和imageurl不同,为什么要隐藏整行?你不想隐藏每行的第一个单元格吗?不,伙计,我不想隐藏pptId,我只想显示gridview的第一行,因为当我单击我的第一个图像时,幻灯片将启动它,如果我使用top(1),我只想要该pptId的第一个图像查询然后我的lightbox将只显示该图像而不是幻灯片中的所有图像这就是为什么mate我希望您理解感谢使您的代码是好的,但它也会使gridview的其他行的值为假,我不希望我只是想隐藏它们,但它们的值应该是功能性的。。我无法提升你的ans,因为我的声誉很低,无法接受这个答案。你如何使用你的lightbox访问值?我编辑我的问题c我更新的问题查看我的aspx页面代码我的朋友我可以使用css,但我的图像路径来自数据库,告诉我如何使用它。。我只是想问,有没有可能像www.slideshare.net网站那样做到这一点,但它现在是自动幻灯片放映的,不管你的数据来自哪里。使用上述css,您只需隐藏表中的每一行,第一行除外。这些行仍将在生成的标记中,并且仍然可以通过javascript访问,但不会显示在屏幕上。嗨,rusmus,它们是随机生成的行和列。我假设您正在为lightbox使用js库。你能告诉我是哪一个吗?@Amitesh我已经用一个更好的浏览器支持更新了我的答案。希望能有帮助。
<!DOCTYPE html>
<html>
<head>
    <style type="text/css">
        table.Grid tr:nth-child(n + 3) {
            display: none;
        }
    </style>
</head>
<body>
    <form runat="server">
    <asp:GridView runat="server" CssClass="Grid">
        <%--Your templates here--%>
    </asp:GridView>
    </form>
</body>
</html>
table.Grid tr + tr + tr{    
    display: none;
}