在ASP.NET控件转发复选框图像 [英] Checkbox for images in an ASP.NET repeater controls
问题描述
我与ASP.NET工作。我使用一个中继器来显示图像,我也正在使用的每个图像的复选框。
I am working with ASP.NET. I am using a repeater to display images, and I also am using a check box for each image.
如何选择单个图像和更新它们的值按图片ID?
How can I select individual images and update their values as per image id?
我的code是:
protected void Button3_Click(object sender, EventArgs e)
{
foreach (RepeaterItem ritem in Repeater1.Items)
{
CheckBox btn = ritem.FindControl("CheckBox1") as CheckBox;
if (btn.Checked == true)
{
string chrck = btn.Text;
}
}
}
这在我的控制,我有使用:
This my control which i have use :
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<br />
<img ID="ImageZoom" runat="server"
src='<%# DataBinder.Eval(Container.DataItem, "ImageUrl") %>'
style="display: inline; height:auto; left: 0pt; top: 0pt;
width:auto;" />
<asp:CheckBox ID="CheckBox1" runat="server" Enabled="True"
Text='<%# DataBinder.Eval(Container.DataItem, "ImageId") %>'
oncheckedchanged="RepeaterCheckBox_CheckedChanged"/>
</ItemTemplate>
</asp:Repeater>
<br />
<br />
<asp:Button ID="Button1" runat="server" onclick="Button3_Click" Text="Pint" />
但在C#code,我总是让价值器isChecked = FALSE 。即使我选中的复选框,并当我点击的品脱的按钮,我只得到虚假的。我怎样才能解决这个问题?如果我选中该复选框,它应该返回true。
But in c# code, I am always getting IsChecked value = false . Even if I checked Checkbox and also when I click on pint button, I am getting only false . How can I solve this? If I checked the checkbox , it should return true.
推荐答案
尝试的ItemDataBound
和的FindControl
try with ItemDataBound
and FindControl
void Repetarer_ItemDataBound(Object Sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
var control = e.Item.FindControl("CheckBox1") as CheckBox;
string result = control.Text;
.....
}
}
这篇关于在ASP.NET控件转发复选框图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!