在 ASP.net 中选中复选框时使用中继器中的数据

发布于 2024-08-08 01:48:29 字数 168 浏览 3 评论 0原文

我有一个中继器来显示我的数据。该中继器显示 2 个字段,其中一个字段是复选框控件,另一个字段是标签。

现在,当复选框被选中时,我如何理解标签的文本?

我想在复选框被选中的每一行中查看标签文本。

我该怎么办?

我使用 LINQtoSQL 从数据库获取和设置数据

I have a repeater for showing my data . this repeater showing 2 field that one of feild is checkBox Control and other is a lable.

NOW , how can I understand text of lable when the checkBox is Checked?

I want to see text of lable in evry row that the CheckBoxes is checksd.

how do I do?

I use LINQtoSQL for get and set data from database

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

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

发布评论

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

评论(3

朕就是辣么酷 2024-08-15 01:48:29

在回发时,您需要循环遍历中继器的每一行,并取出复选框控件。然后您可以访问它的 .Checked 和 .Text 属性。如果它是 .Checked,则将其添加到列表或数组中。如果需要我可以详细说明..

On postback, you need to loop through every row of your repeater, and grab out the checkbox control. Then you can access it's .Checked and .Text properties. If it's .Checked, then add it to a list or array. I can elaborate if needed..

━╋う一瞬間旳綻放 2024-08-15 01:48:29

页面...

             <asp:CheckBox ID="chkBoxID" runat="server" OnCommand="doSomething_Checked" CommandArgument="<%# Some Binding Information%>"
                CommandName="NameForArgument">
             </asp:CheckBox>

后面的代码...

protected void doSomething_Checked(object sender, CommandEventArgs e) {

                CheckBox ctrl = (CheckBox)sender;
                RepeaterItem rpItem = ctrl.NamingContainer as RepeaterItem;
                if (rpItem != null) {
                    CheckBox chkBox = (LinkButton)rpItem.FindControl("chkBoxID");
                    chkBox.DoSomethingHere...
             }
        }

Page...

             <asp:CheckBox ID="chkBoxID" runat="server" OnCommand="doSomething_Checked" CommandArgument="<%# Some Binding Information%>"
                CommandName="NameForArgument">
             </asp:CheckBox>

Code Behind...

protected void doSomething_Checked(object sender, CommandEventArgs e) {

                CheckBox ctrl = (CheckBox)sender;
                RepeaterItem rpItem = ctrl.NamingContainer as RepeaterItem;
                if (rpItem != null) {
                    CheckBox chkBox = (LinkButton)rpItem.FindControl("chkBoxID");
                    chkBox.DoSomethingHere...
             }
        }
淤浪 2024-08-15 01:48:29
<asp:Repeater ID="rptX" runat="server">
<ItemTemplate>
    <asp:Label ID="lblX" runat="server" Visible='<%# Eval("IsChecked") %>' />
    <asp:CheckBox ID="chkX" runat="server" Checked='<%# Eval("IsChecked") %>' />
</ItemTemplate>
</asp:Repeater>

当您分配数据时,代码隐藏

   rptX.DataSource = SomeIEnumerableFromLinq; // which has a bool field called IsChecked
   rptX.DataBind();
<asp:Repeater ID="rptX" runat="server">
<ItemTemplate>
    <asp:Label ID="lblX" runat="server" Visible='<%# Eval("IsChecked") %>' />
    <asp:CheckBox ID="chkX" runat="server" Checked='<%# Eval("IsChecked") %>' />
</ItemTemplate>
</asp:Repeater>

And code behind when you assign your data

   rptX.DataSource = SomeIEnumerableFromLinq; // which has a bool field called IsChecked
   rptX.DataBind();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文