I am new to ASP.Net and I'm not sure if I will do it right. I have a repeater associated with a list of Image objects. Inside each RepeaterItem there is a checkbox, and I have an OnClick event on the button that I want to display some attributes of objects with checked images.
The label is updated, but the metadata is empty. DataBinder.Eval (i.DataItem, "FileName") is coming back, but I'm not sure why? I thought that maybe the feedback from the checkbox is causing problems, but I still get the same problem if I try to display the data before any callbacks occur, so maybe I am getting the attributes incorrectly. Or am I completely wrong about this? Any help was appreciated.
the code:
protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { string importPath = Server.MapPath("~/Images/ForImport"); ImageProcessor processor = new ImageProcessor(importPath); rptImageList.DataSource = processor.ImageList; rptImageList.DataBind(); } } protected void btnImport_Click(object sender, EventArgs e) { foreach (RepeaterItem i in rptImageList.Items) { CheckBox chk = i.FindControl("chkSelectImage") as CheckBox; if (chk.Checked) { Testlabel.Text += "Selected: " + DataBinder.Eval(i.DataItem, "FileName"); } } }
HTML:
<asp:Repeater ID="rptImageList" runat="server"> <ItemTemplate> <div class="photoinstance"> <asp:Image runat="server" ImageUrl='<%#"Images/ForImport/" +DataBinder.Eval(Container.DataItem, "FileName") %>' /> <asp:CheckBox ID="chkSelectImage" AutoPostBack="true" runat="server"/> <p><%#Eval("FileName")%> - <%#Eval("FileSize")%> bytes</p> </div> </ItemTemplate> </asp:Repeater>
Ant p source share