1、可以不用table展示数据
<asp:Repeater ID="Repeater1" runat="server"> <ItemTemplate> <div class="item"> <img src='<%#Eval("pic") %>' />//显示图片 <p><%#Eval("name") %></p> <p><%#Eval("price") %></p> <p><%#Eval("context") %></p> </div> </ItemTemplate> </asp:Repeater>
2、向表中添加表的路径
string path = "Images/" + FileUpload1.FileName;//绝对路径 FileUpload1.SaveAs(Server.MapPath(path));//上传 c.pic = path;//添加路径
//判断是否选择文件
if (!File1.HasFile) { Alert("请选择文件!"); return; }
3、Repeater的command功能
前台
CommandArgument记录主键值CommandName 名字
<td> <asp:Button ID="Button1" CommandName="Delete" CommandArgument=<%#Eval("UserName") %> runat="server" Text="删除" /> <asp:Button ID="Button2" CommandName="Update" CommandArgument=<%#Eval("UserName") %> runat="server" Text="修改" /> </td>
后台
ItemCommand事件
void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e) { if (e.CommandName == "Delete") { new UsersData().Delete(e.CommandArgument.ToString()); } }