<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="DataList.aspx.cs" Inherits="FileUpload自动上传文件.DataList" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <style type="text/css"> .style1{ width:784px; } .style2 { width:126px; } </style> </head> <body> <form id="form1" runat="server"> <div> <asp:DataList ID ="dataList1" runat ="server" RepeatColumns ="1" GridLines ="Both" RepeatLayout ="Table" RepeatDirection ="Horizontal" onitemcommand="dataList1_ItemCommand" oneditcommand="dataList1_EditCommand" oncancelcommand="dataList1_CancelCommand" ondeletecommand="dataList1_DeleteCommand" onselectedindexchanged="dataList1_SelectedIndexChanged" onupdatecommand="dataList1_UpdateCommand" DataKeyField ="Id" > <HeaderTemplate ><%--页眉模版,和Repeater稍微不同,一般每个模版如果用到了table都应该在当前模版闭合,即当前模版用<table></table>包裹,而不是把<table>放在HeaderTemplate</table>放在FooterTemplate闭合,--%> <table><%--因为如果按照后者做会使得RepeatColumns不生效,RepeatColumns意思的每行显示的项个数,即显示多少个ItemTemplate,一般只会显示一项因为这样每列的标题和每列的内容容易对齐,如果不对齐需要用样式设置每列的宽度使其对齐--%> <tr class="style1"> <th class="style2">标题1</th> <th class="style2">标题2</th> <th class="style2">标题3</th> <th class="style2">标题4</th> <th class="style2">时间</th> </tr> </table> </HeaderTemplate> <ItemTemplate> <table > <tr class="style1"> <td class="style2"><%#DataBinder.Eval(Container.DataItem,"title1")%></td> <td class="style2"><%#DataBinder.Eval(Container.DataItem, "title2")%></td> <td class="style2"><%#DataBinder.Eval(Container.DataItem, "title3")%></td> <td class="style2"><%#DataBinder.Eval(Container.DataItem, "title4")%></td> <td class="style2"><%#DateTime.Now.ToString()%></td> <td class="style2" id ="td"> <ul> <li><asp:LinkButton id ="LinkButton2" runat ="server" CommandName ="edit" Text ="edit" ></asp:LinkButton></li> <li><asp:LinkButton id ="LinkButton1" runat ="server" CommandName ="select" Text ="select" ></asp:LinkButton></li> <li><asp:LinkButton id ="LinkButton3" runat ="server" CommandName ="delete" Text ="删除" ></asp:LinkButton></li> </ul> </td> </tr> </table> </ItemTemplate> <SelectedItemTemplate ><%--SelectedItemTemplate一般选中后需要呈现不同的控件才需要使用这个模版,如果只是样式不同只需要设置SelectedItemStyle--%> <table > <tr class="style1"> <td class="style2" style="color:Red;"><asp:TextBox ID ="txtTitle1" runat ="server" Text ='<%#DataBinder.Eval(Container.DataItem, "title1")%>'></asp:TextBox></td> <td class="style2"><asp:TextBox ID ="txtTitle2" runat ="server" Text ='<%#DataBinder.Eval(Container.DataItem, "title2")%>'></asp:TextBox></td> <td class="style2"><asp:TextBox ID ="txtTitle3" runat ="server" Text ='<%#DataBinder.Eval(Container.DataItem, "title3")%>'></asp:TextBox></td> <td class="style2"><asp:TextBox ID ="txtTitle4" runat ="server" Text ='<%#DataBinder.Eval(Container.DataItem, "title4")%>'></asp:TextBox></td> <td class="style2"><%#DateTime.Now.ToString()%></td> <td class="style2" id ="td"> <ul> <li><asp:LinkButton id ="Linkcancel" runat ="server" CommandName ="cancelselect" Text ="取消选中" ></asp:LinkButton></li> </ul> </td> </tr> </table> </SelectedItemTemplate> <EditItemTemplate ><%--EditItemTemplate一般用于编辑时程序文本框给用户输入--%> <table > <tr class="style1"> <td class="style2" style="color:Red;"><asp:TextBox ID ="txtTitle1" runat ="server" Text ='<%#DataBinder.Eval(Container.DataItem, "title1")%>'></asp:TextBox></td> <td class="style2"><asp:TextBox ID ="txtTitle2" runat ="server" Text ='<%#DataBinder.Eval(Container.DataItem, "title2")%>'></asp:TextBox></td> <td class="style2"><asp:TextBox ID ="txtTitle3" runat ="server" Text ='<%#DataBinder.Eval(Container.DataItem, "title3")%>'></asp:TextBox></td> <td class="style2"><asp:TextBox ID ="txtTitle4" runat ="server" Text ='<%#DataBinder.Eval(Container.DataItem, "title4")%>'></asp:TextBox></td> <td class="style2"><%#DateTime.Now.ToString()%></td> <td class="style2" id ="td"> <ul> <li><asp:LinkButton id ="Linkupdate" runat ="server" CommandName ="update" Text ="更新" ></asp:LinkButton></li> <li><asp:LinkButton id ="Linkcancel" runat ="server" CommandName ="cancel" Text ="取消" ></asp:LinkButton></li> </ul> </td> </tr> </table> </EditItemTemplate> <FooterStyle BackColor="#990000" Font-Bold="true" ForeColor="White" /> <AlternatingItemStyle BackColor="White" /> <ItemStyle BackColor="#FFFBD6" ForeColor="#333333" /> <SeparatorStyle BorderStyle="Dashed" /> <SelectedItemStyle BackColor="#FFCC66" Font-Bold="true" ForeColor="Navy" /> <FooterTemplate ></FooterTemplate> </asp:DataList> </div> </form> </body> </html>
相关文章: