2

看来我今天有很多问题。

我想要做的是保存每个图像的文本。目前,我正在将每张图片的正确文本放入文本框中。

后面的代码:

var car = GarageBLL.LoadCar(Convert.ToInt32(CarId),
Convert.ToInt32(_memberId)); ImageRepeater.DataSource = car.Images;
ImageRepeater.DataBind();

protected void FinalizeNewCar(object sender, EventArgs e) {
Response.Redirect("/amcargarasjen"); }
**Code here for saving each edit into the right ImageId.**

ASP:

<asp:Repeater runat="server" ID="ImageRepeater">
   <ItemTemplate>
       <table>
           <tr>
               <td>
                   <a class="deleteLink" href="#" rel="<%#Eval("ImageId")%>" title="">
                   <asp:Image runat="server" ImageUrl="/Content/Images/Garage/DeleteButton.png" /></a>
                   <asp:Image Width="60" Height="45" ID="ImgCar" ImageUrl='<%# String.Format("/garageimages/{0}/{1}.{2}", CarId, Eval("ImageId"), Eval("Extension")) %>' runat="server" />
                   <asp:TextBox runat="server" Text='<%# Eval("Description") %>' ID="txtText"></asp:TextBox>
               </td>
           </tr>
       </table>
   </ItemTemplate>
</asp:Repeater>
<br />
<asp:Button ID="Button1" runat="server" Text="Fullfør" OnClick="FinalizeNewCar" />

有人对如何做到这一点有任何想法吗?

4

1 回答 1

2

修改您的转发器 HTML 标记,如下所示。请注意添加了一个隐藏字段以保留当前图像 ID 的引用。

<asp:Repeater runat="server" ID="ImageRepeater">
   <ItemTemplate>
       <table>
           <tr>
               <td>
                   <a class="deleteLink" href="#" rel="<%#Eval("ImageId")%>" title="">
                   <asp:Image runat="server" ImageUrl="/Content/Images/Garage/DeleteButton.png" /></a>
                   <asp:Image Width="60" Height="45" ID="ImgCar" ImageUrl='<%# String.Format("/garageimages/{0}/{1}.{2}", CarId, Eval("ImageId"), Eval("Extension")) %>' runat="server" />
                   <asp:TextBox runat="server" Text='<%# Eval("Description") %>' ID="txtText"></asp:TextBox>
                   <asp:HiddenField runat="server" Value='<%# Eval("ImageId") %>' ID="txtImageId"></asp:TextBox> 
               </td>
           </tr>
       </table>
   </ItemTemplate>
</asp:Repeater>
<br />
<asp:Button ID="Button1" runat="server" Text="Fullfør" OnClick="FinalizeNewCar" />

代码 FinalizeNewCar 事件处理程序

protected void FinalizeNewCar(object sender, EventArgs e)
{
    foreach (RepeaterItem item in ImageRepeater.Items)
    {
        Int32 imageId = Convert.ToInt32(((HiddenField) item.FindControl("txtImageId")).Value);
        string description = ((TextBox)item.FindControl("txtText")).Text;
        //You will get the imageId description here. 
        //Write your code to update the datatbase.
    }
}
于 2012-11-05T19:55:06.280 回答