编辑 asp 转发器中的特定行
我有一个中继器,在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在描述中,您将从页面 URL 的查询字符串中检索类别标识符。此请求将为所有 Repeater 项返回相同的值,因此每个“catName”和“catImg”HtmlTableRow 将被隐藏。
我假设您希望根据存储在绑定到中继器的数据源中的某些值来隐藏行。
为此,您需要访问 ItemDataBound 事件中的 DataItem 并执行检查以确定哪个项目需要隐藏该行。
下面我将一个字符串列表绑定到 Repeater,因此我可以访问每个项目并执行检查,如下所示,仅隐藏 ItemTemplate 中的 HtmlTableRow,其中 DataItem 的值等于“Item 1”:
我假设您正在绑定某些内容更复杂,例如 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":
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.
我会考虑使用 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.
我得到了它。
感谢所有帮助过的人
I got it.
Thanks to all that helped