显示和隐藏中继器中的特定列?

发布于 2024-12-15 11:47:53 字数 1436 浏览 2 评论 0原文

我有一个复读机。我想隐藏和显示特定条件的特定列。我有三种类型的主题,它们的 id 分别是 0,1,2。现在我想在主题仅为 2 时显示该特定列..

我的代码是:-

 <table id="table1" class="yui" cellpadding="0" cellspacing="0">
                <thead>
                    <tr>
                        <th>
                            <a href='#' title="Click Header to Sort">EmpID #</a>
                        </th>
<th>Edit</th>

                    </tr>
                </thead>
                <tbody>
                    <asp:Repeater ID="Repaddressorbbl" runat="server" OnItemCommand="Repaddressorbbl_ItemCommand">
                        <ItemTemplate>

                            <tr id="gh" style="cursor: pointer" onclick="Select(this);">
                                <td style="text-align: center;">
                                    <%#Eval("empid")%>
                                </td>  
 <td>
                                    <asp:LinkButton ID="lknumber" runat="server" Text="Edit" CommandName="subjectid" />
                                </td>                             
                            </tr>
                        </ItemTemplate>
                    </asp:Repeater>
                </tbody>
                <tfoot>

                </tfoot>
            </table>

I have a repeater. And i want to hide and display a particular column for a particular condition. I have three types of subjects and their ids are 0,1,2 respectively. Now i want to show that particular column when the subject will be 2 only..

My code is :-

 <table id="table1" class="yui" cellpadding="0" cellspacing="0">
                <thead>
                    <tr>
                        <th>
                            <a href='#' title="Click Header to Sort">EmpID #</a>
                        </th>
<th>Edit</th>

                    </tr>
                </thead>
                <tbody>
                    <asp:Repeater ID="Repaddressorbbl" runat="server" OnItemCommand="Repaddressorbbl_ItemCommand">
                        <ItemTemplate>

                            <tr id="gh" style="cursor: pointer" onclick="Select(this);">
                                <td style="text-align: center;">
                                    <%#Eval("empid")%>
                                </td>  
 <td>
                                    <asp:LinkButton ID="lknumber" runat="server" Text="Edit" CommandName="subjectid" />
                                </td>                             
                            </tr>
                        </ItemTemplate>
                    </asp:Repeater>
                </tbody>
                <tfoot>

                </tfoot>
            </table>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

ぃ双果 2024-12-22 11:47:53

如果(主题)项 id 为 2,您可以捕获转发器的 OnItemDataBound 事件并隐藏该列。

为了获得对该列的引用,请将其设为服务器控件:

<td style="text-align: center;" id="COL_TO_HIDE" runat="server"><%#Eval("empid")%></td>  

然后在转发器事件中您可以简单地查看控件并隐藏它:

protected void YourRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
    if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
    {
        var subject = (Subject)e.Item.DataItem;
        if (subject.Id == 2)
        {
            var col = e.Item.FindControl("COL_TO_HIDE");
            col.Visible = false;
        }
    }
}

请注意,这只是一个简化的示例,您应该开始使用。

You could catch the OnItemDataBound event of the repeater and hide the column there if the (subject) item id is 2.

In order you can get a reference to the column, make it a server control:

<td style="text-align: center;" id="COL_TO_HIDE" runat="server"><%#Eval("empid")%></td>  

Then in the repeater event you can simply look for the control and hide it:

protected void YourRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
    if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
    {
        var subject = (Subject)e.Item.DataItem;
        if (subject.Id == 2)
        {
            var col = e.Item.FindControl("COL_TO_HIDE");
            col.Visible = false;
        }
    }
}

Please note, this is just a simplified example which should you get started.

哑剧 2024-12-22 11:47:53

我认为您应该首先使用 来定义表格的开始和结束来整理它。

您可以通过添加 runat="server" 并为列 提供 id 和 runat="server" 属性来让表在服务器上运行,以便您可以针对服务器代码进行编程它。然后,我会根据您的字段值评估绑定单元格的可见属性,或使用 attribute.add("display:none") 或仅使用链接中建议的网格视图。

I think you should start by using <HeaderTemplate></HeaderTemplate> and <FooterTemplate></FooterTemplate> to define the start and end of your table just to tidy it up.

You can get the table to run on the server by adding a runat="server" and give the column <td> an id and a runat="server" attribute so you can program server code against it. I'd then eval bind the visible attribute of the cell based on your field value or use attributes.add("display:none") or just use a grid view as suggested in the link.

瑕疵 2024-12-22 11:47:53
<asp:Repeater ID="Repaddressorbbl" runat="server" 
OnItemCommand="Repaddressorbbl_ItemCommand">
    <ItemTemplate>
        <tr id="gh" style="cursor: pointer" onclick="Select(this);">
            <td style="text-align: center;">
                <%#Eval("empid")%>
            </td>  
            <% if (false){ %>
            <td>
                <asp:LinkButton ID="lknumber" runat="server" 
                 Text="Edit" CommandName="subjectid" />
            </td> 
            <% } %>                             
        </tr>
    </ItemTemplate>
</asp:Repeater>
<asp:Repeater ID="Repaddressorbbl" runat="server" 
OnItemCommand="Repaddressorbbl_ItemCommand">
    <ItemTemplate>
        <tr id="gh" style="cursor: pointer" onclick="Select(this);">
            <td style="text-align: center;">
                <%#Eval("empid")%>
            </td>  
            <% if (false){ %>
            <td>
                <asp:LinkButton ID="lknumber" runat="server" 
                 Text="Edit" CommandName="subjectid" />
            </td> 
            <% } %>                             
        </tr>
    </ItemTemplate>
</asp:Repeater>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文