意见箱
恒创运营部门将仔细参阅您的意见和建议,必要时将通过预留邮箱与您保持联络。感谢您的支持!
意见/建议
提交建议
配置详情
本产品仅限新用户首购专享!每人限购1台,续费5折
当前配置
数据中心: {{ getconfigInfoArea(productDetailInfo) }}
套餐规格: 2 核 2 G
带宽:
系统盘 {{ validateMySplit(ProductVM.getProductappointInfoBykey(productDetailInfo,'云系统盘'),'|',1) }} 性能型
IP 数 1 个
可选配置
操作系统:
VPC:
安全组:
购买时长:
1 月
我已阅读并同意《恒创科技服务协议》
购买前请阅读协议并勾选同意

repeater中如何得到html控件

来源:互联网 编辑:云晓生
2024-04-07 18:00:46

在Repeater控件中获取HTML控件的方法如下:

1、在Repeater控件的ItemTemplate中定义HTML控件,我们可以定义一个Label控件和一个Button控件:

<ItemTemplate>
    <table>
        <tr>
            <td>
                <asp:Label ID="lblName" runat="server" Text='<%# Eval("Name") %>'></asp:Label>
            </td>
            <td>
                <asp:Button ID="btnEdit" runat="server" Text="编辑" OnClick="btnEdit_Click" CommandArgument='<%# Eval("ID") %>' />
            </td>
        </tr>
    </table>
</ItemTemplate>

2、接下来,在Repeater控件的代码后台(Default.aspx.cs)中,为Button控件添加点击事件处理程序:


repeater中如何得到html控件

protected void btnEdit_Click(object sender, EventArgs e)
{
    // 获取Button控件所在的Repeater项(即行)
    RepeaterItem item = (sender as Button).NamingContainer as RepeaterItem;
    // 从Repeater项中获取HTML控件的值
    string name = (item.FindControl("lblName") as Label).Text;
    string id = (item.FindControl("btnEdit") as Button).CommandArgument;
}

3、在需要的地方调用Repeater控件的数据绑定方法,rptDataList.DataBind(),这样,Repeater控件就会根据数据源生成HTML表格,并在每个表格行中显示Label和Button控件,当用户点击Button控件时,可以通过上述方法获取到HTML控件的值。

本网站发布或转载的文章均来自网络,其原创性以及文中表达的观点和判断不代表本网站。
上一篇: 如何下载html文件 下一篇: dede如何重新生成html