编辑 asp 转发器中的特定行

发布于 2024-12-02 07:02:45 字数 818 浏览 4 评论 0原文

我有一个中继器,在 dataItembound 上我有类似的东西,

((HtmlTableRow)e.Item.FindControl("prodName")).Visible = false;

但这将中继器中的所有表行设置为不可见。我想隐藏一个特定的。有办法做到这一点吗?

这是完整的小鬼

 protected void RepeaterCategories_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
  if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
    {
        //Get category id
        string catId = Request.QueryString["stctid"];
        //Call function to check stock levels in the next loaded category
        bool stock = checkCategoryStockLevels(catId);

        if(stock == true)
        {
            ((HtmlTableRow)e.Item.FindControl("catName")).Visible = false;
            ((HtmlTableRow)e.Item.FindControl("catImg")).Visible = false;
        }
}

I have a repeater and on dataItembound i have something like this

((HtmlTableRow)e.Item.FindControl("prodName")).Visible = false;

This however sets all tablerows in the repeater to be invisible. I would like a specific one to be hidden. Is there a way to do this?

Heres the full imp

 protected void RepeaterCategories_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
  if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
    {
        //Get category id
        string catId = Request.QueryString["stctid"];
        //Call function to check stock levels in the next loaded category
        bool stock = checkCategoryStockLevels(catId);

        if(stock == true)
        {
            ((HtmlTableRow)e.Item.FindControl("catName")).Visible = false;
            ((HtmlTableRow)e.Item.FindControl("catImg")).Visible = false;
        }
}

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

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

发布评论

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

评论(3

Spring初心 2024-12-09 07:02:45

在描述中,您将从页面 URL 的查询字符串中检索类别标识符。此请求将为所有 Repeater 项返回相同的值,因此每个“catName”和“catImg”HtmlTableRow 将被隐藏。

我假设您希望根据存储在绑定到中继器的数据源中的某些值来隐藏行。

为此,您需要访问 ItemDataBound 事件中的 DataItem 并执行检查以确定哪个项目需要隐藏该行。

下面我将一个字符串列表绑定到 Repeater,因此我可以访问每个项目并执行检查,如下所示,仅隐藏 ItemTemplate 中的 HtmlTableRow,其中 DataItem 的值等于“Item 1”:

string dataItem = (string)e.Item.DataItem;
if (dataItem == "Item 1")
{
    ((HtmlTableRow)e.Item.FindControl("prodName")).Visible = false;   
}

我假设您正在绑定某些内容更复杂,例如 DataRow 或其他一些对象。无论哪种方式,过程都是相同的,转换 DataItem 并执行检查。

In the description you are retrieving the category identifier from the query string of the pages URL. This request will return the same value for all Repeater items and as such every "catName" and "catImg" HtmlTableRow will be hidden.

I assume you wish to hide the rows based on some value stored in the DataSource being bound to the repeater.

To do so you will need to access the DataItem in the ItemDataBound event and perform a check to determine which item requires the row to be hidden.

Below I have bound a List of strings to the Repeater, so I can access each item and perform a check like so, hiding only the HtmlTableRow in the ItemTemplate where the value of the DataItem equals "Item 1":

string dataItem = (string)e.Item.DataItem;
if (dataItem == "Item 1")
{
    ((HtmlTableRow)e.Item.FindControl("prodName")).Visible = false;   
}

I assume you are binding something more complex such as a DataRow or some other Object. Either way the process is the same, cast the DataItem and perform your check.

月下凄凉 2024-12-09 07:02:45

我会考虑使用 ListView 或 DataList 来代替,因为这样您就可以使用数据键根据特定值确定行可见性。

I would look into using a ListView or a DataList instead, because then you can use data keys to determine row visibility based on a certain value.

紫轩蝶泪 2024-12-09 07:02:45

我得到了它。

    for (int repeaterCount = 0; count < repeaterID.Items.Count; count++)
    {
        Label label = (Label)repeaterID.Items[repeaterCount].FindControl("labelID");
        label.Text = "Text";
    }

感谢所有帮助过的人

I got it.

    for (int repeaterCount = 0; count < repeaterID.Items.Count; count++)
    {
        Label label = (Label)repeaterID.Items[repeaterCount].FindControl("labelID");
        label.Text = "Text";
    }

Thanks to all that helped

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文