在中继器中检索td的值 [英] Retrieve the value of td in repeater
本文介绍了在中继器中检索td的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个包含表的中继器.我想在转发器项目模板中隐藏表格的一些表格单元格这是ASPX源代码:
I have a Repeater that contains a Table. I want to hide the some tablecells of the table in repeater item template Here is the ASPX source code:
<ItemTemplate>
<table style="width: 100%" align="center">
<tr>
<td style="width: 60px;" align="center">
<img src="upload/companylogo/<%# Eval("companylogo") %>" />
</td>
<td align="left">
<asp:Label runat="server" CssClass="lblcname" ID="Label1" Text='<%# Eval("companyname") %>' /></td>
<td align="right">
<asp:Label runat="server" ID="Label2" Text='<%# Eval("city") %>' /></td>
</tr>
<tr>
<td runat="server" id="address" colspan="3">
<asp:Label runat="server" ID="Label3" Text='<%# Eval("address") %>' />
</td>
</tr>
<tr>
<td colspan="3" align="right" id="vp" runat="server">
<a href='nfonews.aspx?id=<%# Eval("mpid") %>'>view Profile</a>
» Send Inquiry </td>
</tr>
<tr>
<td colspan="3" style="height: 20px; background-image: url(image/stripe_head_bg.png)"></td>
</tr>
</table>
</ItemTemplate>
还有我的代码背后:
SqlDataReader dr = cmd.ExecuteReader();
if (dr.HasRows == true)
{
dr.Read();
if (dr["payment"].ToString() == "Yes")
{
Repeater1.DataBind();
if (Repeater1.Items.Count == 0)
{
Repeater1.Visible = false;
}
else
{
Repeater1.Visible = true;
}
}
}
推荐答案
在网格的ItemDataBound事件中,使用FindControl查找单元格.
In the ItemDataBound event of the grid, use FindControl to find the cell.
添加属性; onitemdatabound ="myRepeater_ItemDataBound"
然后在代码后面
protected void myRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
ListItemType rowType = (ListItemType)e.Item.ItemType;
if (rowType == ListItemType.Pager || rowType == ListItemType.Header || rowType == ListItemType.Footer)
return;
TableCell cell = (TableCell)e.Item.FindControl("address");
}
这篇关于在中继器中检索td的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文