DataList
提供相关的编辑模板,但和DataGrid不一样的是,DataList没有编辑按钮。要在DataList中使用编辑功能,可在项模板中增加一个按钮,Linkbutton和Button都可以。在CommandName中设置为Edit就可以把此按钮和DataList的编辑事件联系起来了。
如:
编辑按钮可以使用 CommandName="Edit"
更新按钮可以使用CommandName="Update"
取消按钮可以使用CommandName="Cancel"
删除按钮可以使用CommandName="Delete"
来实现。
-------------------------------------------------------------------------------------------------------------------------
控件设置:
<asp:DataList ID="UserList" DataKeyField="Uid"
OnItemCreated="UserList_ItemCreated"
OnUpdateCommand="UserList_OnUpdateCommand"
OnDeleteCommand="UserList_OnDeleteCommand" runat="server"
Width="100%" RepeatColumns="6"
OnEditCommand="UserList_OnEditCommand"
OnCancelCommand="UserList_OnCancelCommand">
<HeaderTemplate>
<table width="100%" border="0" cellpadding="0"
cellspacing="0" bgcolor="#E2EEF5" >
<tr>
<td width="17%" height="25" align="center"
bgcolor="#E8F0F7">登陆名称</td>
<td width="15%" align="center"
bgcolor="#E8F0F7">真实姓名</td>
<td width="17%" align="center"
bgcolor="#E8F0F7">所属用户组</td>
<td width="25%" align="center"
bgcolor="#E8F0F7">拥有权限</td>
<td width="14%" align="center"
bgcolor="#E8F0F7">创建时间</td>
<td width="12%" align="center"
bgcolor="#E8F0F7">操作</td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td height="25"
bgcolor="#FFFFFF"><img
src="images/FriendICO.gif" width="15" height="15"
style="margin-left:5px;"
/> [<%#eval_r("Uname")%>]<asp:Image
ID="StateICO"
ImageUrl='<%#GetUserState(eval_r("uState").ToString())
%>' width="12" height="12" runat="server"
/></td>
<td align="center"
bgcolor="#FFFFFF"><%#eval_r("Rname")%></td>
<td align="center"
bgcolor="#FFFFFF"><%#eval_r("UserGroup")%></td>
<td align="center"
bgcolor="#FFFFFF"><%#eval_r("Purview")%></td>
<td align="center"
bgcolor="#FFFFFF"><%#eval_r("Ctimes","{0:d}")%></td>
<td align="center"
bgcolor="#FFFFFF"><img
src="images/Edit_ICOS.gif" width="14" height="15" border="0"
align="absmiddle" />
<asp:LinkButton CommandName="Edit" <%-- linkButton定义时没有onclick方法的定义
--%>
ID="Edit_But" ForeColor="#003366"
runat="server">编辑</asp:LinkButton> <img
src="images/DEL_ICOS.gif" width="14" height="15" border="0"
align="absmiddle" /><asp:LinkButton
CommandName="Delete"
ID="Del_But" ForeColor="#003366" runat="server"
>删除</asp:LinkButton></td>
</tr>
</ItemTemplate>
<EditItemTemplate>
<tr>
<td height="25"
bgcolor="#E8F0F7"><img
src="images/FriendICO.gif" width="15" height="15"
style="margin-left:5px;"
/> <%#eval_r("Uname")%><asp:CheckBox
ID="User_State"
Checked='<%#GetBoxState(eval_r("uState").ToString().Trim())
%>' runat="server" Text="启用账户"
/>
</td>
<td align="center"
bgcolor="#E8F0F7"><asp:TextBox
ID="User_Rname" runat="server" CssClass="inputX"
Text='<%#eval_r("Rname")%>'
Width="80px"></asp:TextBox>
</td>
<td align="center"
bgcolor="#E8F0F7">
<asp:DropDownList ID="User_Group" runat="server"
CssClass="FontBlue12">
<asp:ListItem
Value="Guest">来宾组</asp:ListItem>
<asp:ListItem
Value="Editor">编辑组</asp:ListItem>
<asp:ListItem
Value="System">系统组</asp:ListItem>
</asp:DropDownList>
</td>
<td align="center"
bgcolor="#E8F0F7">
<asp:CheckBoxList ID="User_Priv" runat="server"
CssClass="FontBlue12"
RepeatDirection="Horizontal">
<asp:ListItem
Value="r">读</asp:ListItem>