Asp.net的datalist的button这种控件激发后台事件问题

程序猿_枫三少 2013-12-29 02:43:01
前台代码

<%@ Page Language="C#" AutoEventWireup="true"  EnableEventValidation="false"  CodeFile="UserInfo.aspx.cs"  Inherits="JiaoYou_Admin_AdminInfo" %>

<!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>
</head>
<body>
<form id="form1" runat="server">
<asp:DataList ID="DataList1" runat="server"
OnDeleteCommand="DataList1_DeleteCommand" DataKeyField="UserName"
OnUpdateCommand="DataList1_UpdateCommand"
BorderColor="Tan" BorderWidth="1px" CellPadding="2" ForeColor="Black"
Height="188px" Width="499px" Font-Size="Smaller">
<HeaderTemplate>
<table border="1" align="center" width="100%">
<tr style=" width:100%" align="center" style="color:#999">
<td style="margin-left:10px;">会员名</td>
<td style=" margin-left:10px;">账户名</td>
<td style=" margin-left:10px;">性别</td>
<td style=" margin-left:10px;">出生日期</td>
<td style=" margin-left:10px;">婚姻状态</td>
<td style=" margin-left:10px;">删除</td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr style=" color:#999" >
<td style="margin-left:10px;"> <%# DataBinder.Eval(Container.DataItem, "NickName")%></td>
<td style="margin-left:10px;"><%#DataBinder.Eval(Container.DataItem, "UserName")%></td>
<td style="margin-left:10px;"><%#DataBinder.Eval(Container.DataItem, "Sex")%></td>
<td style="margin-left:10px;"><%#DataBinder.Eval(Container.DataItem, "BirthDay")%></td>
<td style="margin-left:10px;"><asp:Button ID="Mod" runat ="server" Text ="编辑" CommandName ="Update"/></td>
<td style="margin-left:10px;"><asp:Button ID="Del" runat ="server" Text ="删除" CommandName= "Delete"/></td>
</tr>
</ItemTemplate>
<FooterTemplate></table></FooterTemplate>
<FooterStyle />
<SelectedItemStyle />
<AlternatingItemStyle />
<HeaderStyle Font-Bold="True" />
</asp:DataList>
<br />
</form>
</body>
</html>




后台代码

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class JiaoYou_Admin_AdminInfo : System.Web.UI.Page
{
UserInfo user = new UserInfo();
protected void Page_Load(object sender, EventArgs e)
{
DataSet ds = user.select();
DataList1.DataSource = ds;
DataList1.DataBind();
}
protected void DataList1_UpdateCommand(object source, DataListCommandEventArgs e)
{
string username = this.DataList1.DataKeyField[e.Item.ItemIndex].ToString();
DataSet ds = user.select_username(username);
DataList1.DataSource = ds;
DataList1.DataBind();
}
protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
{
if (e.CommandName == "Bianji")
{
TextBox1.Text = "123123";
}
}
protected void DataList1_DeleteCommand(object source, DataListCommandEventArgs e)
{

}
}
...全文
136 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
枫飞叶 2013-12-30
  • 打赏
  • 举报
回复
直接把事件绑定在按钮上
WUCIDECIWEI 2013-12-29
  • 打赏
  • 举报
回复
  • 打赏
  • 举报
回复
我的意思就是为什么激发不了后台事件体,我标题写了的
  • 打赏
  • 举报
回复
刷新页面是要重新绑定数据源的,你写的这个是什么意思?
  • 打赏
  • 举报
回复
我之前把 DataList1_UpdateCommand 改成这样的

protected void DataList1_UpdateCommand(object source, DataListCommandEventArgs e)
    {
        TextBox1.Text = "123123";
    }
就是刷新当前页面 ,无反应啊!
  • 打赏
  • 举报
回复
点击编辑 就是刷新页面 毫无反应啊

62,047

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧