0

我有 asp.net 中继器控制器,我试图获取隐藏字段的值CheckBox1_CheckedChanged

<ul id="sortable">
    <asp:Repeater runat="server" ID="rep_sortable">
        <ItemTemplate>
            <li class="ui-state-default">
               <span class="ui-icon ui-icon-arrowthick-2-n-s"></span>
               <%# DataBinder.Eval(Container.DataItem, "Body") %> 
               <%# DataBinder.Eval(Container.DataItem, "Completed") %> 
               <asp:CheckBox ID="chb_com"  runat="server" AutoPostBack="True" Checked='<%# DataBinder.Eval(Container.DataItem, "Completed")  %>' oncheckedchanged="CheckBox1_CheckedChanged"/>
               <asp:HiddenField ID="hf_reminderID" runat="server" Value='<%# DataBinder.Eval(Container.DataItem, "ReminderID")  %>'/>
            </li>
        </ItemTemplate>
    </asp:Repeater>
</ul>

C#

protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
{
   foreach()
}
4

2 回答 2

0

您可以使用NamingContainer来查找同级控件。

protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
{
    var checkBox = (CheckBox) sender;
    var reminderHiddenField = (HiddenField)checkBox.NamingContainer
        .FindControl("hf_reminderID");
}
于 2013-02-27T20:10:24.540 回答
0

此代码应该可以工作:

protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
        {
            var checkBox = sender as CheckBox;
            var hiddenField = checkBox.Parent.FindControl("hf_reminderID") as HiddenField;
            var value = hiddenField.Value;
        }
于 2013-02-27T20:13:03.997 回答