| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 471 人关注过本帖
标题:[求助]WEB动态添加按钮问题
只看楼主 加入收藏
礼拜六
Rank: 1
等 级:新手上路
帖 子:22
专家分:0
注 册:2006-4-5
收藏
 问题点数:0 回复次数:0 
[求助]WEB动态添加按钮问题

protected void buttonlook_Click(object sender, EventArgs e)
{
string sqlstring = "select * from liuyan ";
DataBase db = new DataBase();
DataTable dt = db.GetDataTable(sqlstring);
Button [] bt = new Button[50];
Label[] lb = new Label[50];
Panel[] pa = new Panel[50];

int l = 0;
for (int i = 0; i < dt.Rows.Count && i < 50; i++)
{
l = i + 1;
lb[i] = new Label();
bt[i] = new Button();
pa[i] = new Panel();
System.Drawing.Color c = System.Drawing.ColorTranslator.FromHtml("#000080");
lb[i].ForeColor = c;
lb[i].Font.Bold = true;
lb[i].Text = "留言内容:" + "&nbsp;&nbsp;&nbsp;&nbsp;" + "第" + l + "条" + "<br>"
+ "<br>" + "姓名:" + "&nbsp;&nbsp;&nbsp;&nbsp;" + dt.Rows[i]["mingcheng"].ToString() + "<br/>"
+ "电话号码:" + "&nbsp;&nbsp;&nbsp;&nbsp;" + dt.Rows[i]["haoma"].ToString() + "<br/>"
+ "地址:" + "&nbsp;&nbsp;&nbsp;&nbsp;" + dt.Rows[i]["dizhi"].ToString() + "<br/>"
+ "电子邮件:" + "&nbsp;&nbsp;&nbsp;&nbsp;" + dt.Rows[i]["youjian"].ToString() + "<br/>"
+ "留言内容: " + "&nbsp;&nbsp;&nbsp;&nbsp;" + dt.Rows[i]["liuyan"].ToString () + "<br/>";
bt[i].ID = dt.Rows[i]["bianhao"].ToString () ;
bt[i].Text = "删除" ;
pa[i].Controls.Add(lb[i]);
pa[i].Controls.Add(new LiteralControl("<br><br>"));
pa[i].Controls.Add(bt[i]);
pa[i].BorderWidth = 1;
pa[i].Width = 500;
bt[i].Click += new System.EventHandler(guanli_Click);//没有提示错误,就是点击了动态生成的按钮后,不执行下面的guanli_click方法
Panel1.Controls.Add(new LiteralControl("<br><br>"));
Panel1.Controls.Add(pa[i]);
Panel1.Controls.Add(new LiteralControl("<br><br>"));

}
}

void guanli_Click(object sender, EventArgs e)
{
Button button = sender as Button;
int i = Convert.ToInt32(button.ID);
string sqlstring = "delete from tupian where bianhao = " + i;
DataBase db = new DataBase();
int chenggong = db.ExecuteSQL(sqlstring);
if (chenggong != -1)
{
//System.Web.UI.Page.Response.Write("<Script Language=JavaScript>alert('删除成功!')</script>");
}
else
{
//System.Web.UI.Page.Response.Write("<Script Language=JavaScript>alert('删除失败,请重试!')</script>");
}
}

搜索更多相关主题的帖子: WEB 按钮 动态 
2007-06-18 21:58
快速回复:[求助]WEB动态添加按钮问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.024324 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved