我的前台是这样子写的
<asp:DataList ID="DataList1" runat="server" DataKeyField="userid" CellPadding="3" BackColor="White" BorderColor="#E7E7FF"
BorderStyle="None" BorderWidth="1px" GridLines="Both" RepeatColumns="3" Width="100%" OnCancelCommand="DataList1_CancelCommand" OnEditCommand="DataList1_EditCommand" OnItemCommand="DataList1_ItemCommand" OnUpdateCommand="DataList1_UpdateCommand" OnDeleteCommand="DataList1_DeleteCommand">
<FooterStyle BackColor="#B5C7DE" ForeColor="#4A3C8C" />
<AlternatingItemStyle BackColor="#F7F7F7" />
<ItemStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" HorizontalAlign="Left" VerticalAlign="Middle"
Wrap="False" />
<SelectedItemStyle BackColor="#738A9C" Font-Bold="True" ForeColor="#F7F7F7" />
<HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#F7F7F7" />
<HeaderTemplate>
所有创建的用户</HeaderTemplate>
<ItemTemplate>
<asp:LinkButton ID="linkbutton1" runat="server" CommandName="select">查看</asp:LinkButton>
<asp:LinkButton ID="linkbutton2" runat="server" CommandName="edit">编辑</asp:LinkButton>
<asp:LinkButton ID="linkbutton3" runat="server" CommandName="delete" OnClientClick='return confirm("确认要删除此行信息吗?")'>删除</asp:LinkButton><br />
用户描述:<%# DataBinder.Eval(Container.DataItem,"memo")%><br />
用户名:<%# DataBinder.Eval(Container.DataItem,"username")%>
</ItemTemplate>
<SelectedItemTemplate>
序号:<%# DataBinder.Eval(Container.DataItem, "userid")%><br />
用户描述:<%# DataBinder.Eval(Container.DataItem,"memo")%><br />
用户名:<%# DataBinder.Eval(Container.DataItem,"username")%><br />
权限:<%# DataBinder.Eval(Container.DataItem,"power")%><br />
</SelectedItemTemplate>
<EditItemTemplate>
<asp:LinkButton ID="linkbutton1" runat="server" CommandName="cancel">取消</asp:LinkButton>
<asp:LinkButton ID="linkbutton2" runat="server" CommandName="update">保存</asp:LinkButton><br />
<asp:TextBox ID="TextBox1" Width="200px" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"memo")%>'></asp:TextBox><br />
<asp:TextBox ID="TextBox2" Width="200px" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"username")%>'></asp:TextBox>
</EditItemTemplate>
</asp:DataList>
我在做删除操作的时候,要得到用户名的数据,要如何做?谢谢!
<asp:DataList ID="DataList1" runat="server" DataKeyField="userid" CellPadding="3" BackColor="White" BorderColor="#E7E7FF"
BorderStyle="None" BorderWidth="1px" GridLines="Both" RepeatColumns="3" Width="100%" OnCancelCommand="DataList1_CancelCommand" OnEditCommand="DataList1_EditCommand" OnItemCommand="DataList1_ItemCommand" OnUpdateCommand="DataList1_UpdateCommand" OnDeleteCommand="DataList1_DeleteCommand">
<FooterStyle BackColor="#B5C7DE" ForeColor="#4A3C8C" />
<AlternatingItemStyle BackColor="#F7F7F7" />
<ItemStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" HorizontalAlign="Left" VerticalAlign="Middle"
Wrap="False" />
<SelectedItemStyle BackColor="#738A9C" Font-Bold="True" ForeColor="#F7F7F7" />
<HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#F7F7F7" />
<HeaderTemplate>
所有创建的用户</HeaderTemplate>
<ItemTemplate>
<asp:LinkButton ID="linkbutton1" runat="server" CommandName="select">查看</asp:LinkButton>
<asp:LinkButton ID="linkbutton2" runat="server" CommandName="edit">编辑</asp:LinkButton>
<asp:LinkButton ID="linkbutton3" runat="server" CommandName="delete" OnClientClick='return confirm("确认要删除此行信息吗?")'>删除</asp:LinkButton><br />
用户描述:<%# DataBinder.Eval(Container.DataItem,"memo")%><br />
用户名:<%# DataBinder.Eval(Container.DataItem,"username")%>
</ItemTemplate>
<SelectedItemTemplate>
序号:<%# DataBinder.Eval(Container.DataItem, "userid")%><br />
用户描述:<%# DataBinder.Eval(Container.DataItem,"memo")%><br />
用户名:<%# DataBinder.Eval(Container.DataItem,"username")%><br />
权限:<%# DataBinder.Eval(Container.DataItem,"power")%><br />
</SelectedItemTemplate>
<EditItemTemplate>
<asp:LinkButton ID="linkbutton1" runat="server" CommandName="cancel">取消</asp:LinkButton>
<asp:LinkButton ID="linkbutton2" runat="server" CommandName="update">保存</asp:LinkButton><br />
<asp:TextBox ID="TextBox1" Width="200px" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"memo")%>'></asp:TextBox><br />
<asp:TextBox ID="TextBox2" Width="200px" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"username")%>'></asp:TextBox>
</EditItemTemplate>
</asp:DataList>
我在做删除操作的时候,要得到用户名的数据,要如何做?谢谢!
if(e.CommandName=="delete")
{
int iIndex=Convert.ToInt16(e.ComandArgument);
GridViewRow gvr=gridview1.Rows[iIndex];
string username=gvr.Cells[列号].Text;
}
这样也许可以