首页 新闻 会员 周边 捐助

如何找到子repeater 中的控件

1
[已解决问题] 解决于 2010-05-18 12:13
代码
<asp:Repeater ID="rpt1" runat="server" onitemdatabound="rpt1_ItemDataBound"
onitemcommand
="rpt1_ItemCommand" >
<ItemTemplate>
<tr height="25" align="left" valign="middle" bgcolor="#ffffff" name="discolorationline">
<td align="center">
<%# DataBinder.Eval(Container.DataItem,"type")%>
</td>
<td style="display:none;"><%# DataBinder.Eval(Container.DataItem, "project_target_id")%></td>
<td>
<table id="tb2" frame="void" cellspacing="1" cellpadding="0" border="0" bgcolor="#95a5d2" width="995">
<asp:Repeater ID="rpt2" runat="server">
<ItemTemplate>
<tr height="25" align="left" valign="middle" bgcolor="#ffffff" name="discolorationline">
<td align="center" width ="630">
<%# Eval("content") %>
</td>
<td align="center" width="60">
<%# Eval("weight") %>
</td>
<td align="center" width="60">
<%# Eval("score") %>
</td>
<td align="center" width="175">
<%# Eval("remark") %>
</td>
<td align="center" width="60">
<asp:ImageButton ID="ImageButton2" runat="server" BorderStyle="None" CommandName="img_click" ImageUrl="~/but_img/cross.png" AlternateText="删除" />
<cc1:ConfirmButtonExtender ID="ConfirmButtonExtender1" runat="server" TargetControlID="ImageButton2" ConfirmText='<%# Alert.Del_info() %>'>
</cc1:ConfirmButtonExtender>
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
</table>
</td>
</tr>
</ItemTemplate>
</asp:Repeater>

 

 

怎样获得 CommandName="img_click"  ? 

<asp:ImageButton ID="ImageButton2" runat="server" BorderStyle="None" CommandName="img_click" ImageUrl="~/but_img/cross.png" AlternateText="删除" />

问题补充: protected void rpt1_ItemDataBound(object sender, RepeaterItemEventArgs e) { if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { Repeater rep = e.Item.FindControl("rpt2") as Repeater;//找到里层的repeater对象 DataRowView rowv = (DataRowView)e.Item.DataItem string project_target_id = rowv["project_target_id"].ToString(); string type_id = rowv["type"].ToString(); rep.DataSource = Get_rpt2(project_target_id, type_id); rep.DataBind(); } } 这个事件是绑定,现在是要找到删除按钮 并把当前行删除掉? 问题是删除按钮找不到。。?
like%'远远'%的主页 like%'远远'% | 小虾三级 | 园豆:635
提问于:2010-05-17 20:42
< >
分享
最佳答案
0

你需要在哪里找这个控件?举两个例子,相关数据可以忽略~

ItemDataBound事件中查找控件:

<asp:HyperLink ID="HLinkModify" NavigateUrl='<%# "Admin_User.aspx?id="+Eval("id")%>' Target="_self" runat="server">点击修改</asp:HyperLink>

        protected void RptUser_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.SelectedItem)
            {
                DataRowView rowv = (DataRowView)e.Item.DataItem;
                if (rowv["username"].ToString() != Session["admin"].ToString())
                {
                    HyperLink HLinkModify = (HyperLink)e.Item.FindControl("HLinkModify");
                    HLinkModify.Visible = false;                     
                }
            }
        }

Rpt中控件的事件使用:
<asp:LinkButton ID="LBtnDel" OnClick="LBtnDel_OnClick" ToolTip='<%# Eval("username") %>' runat="server">删除</asp:LinkButton>

        //Rpt中控件的事件
        protected void LBtnDel_OnClick(object sender,EventArgs e)
        {
            LinkButton LBtnDel = sender as LinkButton;//触发事件的LinkButton
            //RepeaterItem item = LBtnDel.NamingContainer as RepeaterItem;    //LinkButton所在行
            string username = LBtnDel.ToolTip.ToString();
           ...
        }

Astar | 高人七级 |园豆:40805 | 2010-05-18 07:09
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册