我有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()
}
答案 0 :(得分:0)
您可以使用NamingContainer查找同级控件。
protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
{
var checkBox = (CheckBox) sender;
var reminderHiddenField = (HiddenField)checkBox.NamingContainer
.FindControl("hf_reminderID");
}
答案 1 :(得分: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;
}