求助!
大家好我是一名软件设计爱好者,想请教一下,C#语言编写web的相关问题。就是说我点击lablebutton-a,根据判断动态生成多个lablebutton-b,点击lablebutton-b,又能根据判断生成多个lablebutton-c,请问怎么解决这些动态控件的页面刷新问题,现在动态生成的控件都无法响应事件!
万分感谢!! --------------------编程问答-------------------- 动态响应事件比较麻烦,就算你解决了,还会有后续的问题需要解决。
我的做法是用模板列,拖进去按钮,这个按钮的事件是一定容易执行到的,刷不刷新的问题完全不存在。
,
至于如何生成多个按钮,就看你如何存数据了(也可以手动拼出DataTable),然后绑定在Gridview、DataList上。 --------------------编程问答-------------------- 如何生成多个按钮,就看你如何存数据了(也可以手动拼出DataTable),然后绑定在Gridview、DataList上
请问这个有图吗,本人新手,万分感谢 --------------------编程问答-------------------- 那我写点代码吧,等一会儿。
你是用VB还是用C#?是用GridView还是DataList? --------------------编程问答-------------------- 语言C#,谢谢 --------------------编程问答-------------------- http://www.cnblogs.com/chenxizhang/archive/2009/05/19/1460544.html
参考一下这个吧。 --------------------编程问答-------------------- 前台代码:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
<!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: 85px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
当前共有<asp:Label ID="Label1" runat="server" Text="2"></asp:Label>
<asp:Button ID="Button3" runat="server" Text="增加" onclick="Button3_Click" />
<asp:Button ID="Button2" runat="server" Text="减少" onclick="Button2_Click" />
<asp:DataList ID="DataList1" runat="server">
<ItemTemplate>
<table style="width:100%;">
<tr>
<td class="style1">
随便布局</td>
<td>
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
</td>
<td>
</td>
</tr>
<tr>
<td class="style1">
根据需要</td>
<td>
</td>
<td>
</td>
</tr>
<tr>
<td class="style1">
</td>
<td>
</td>
<td>
</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>
<asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
</form>
</body>
</html>
后台代码:
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
BindDL();
}
}
protected void Button3_Click(object sender, EventArgs e)
{
//增加
Label1.Text = (Convert.ToInt16(Label1.Text) + 1).ToString();
BindDL();
}
protected void Button2_Click(object sender, EventArgs e)
{
//减少
Label1.Text = (Convert.ToInt16(Label1.Text) - 1).ToString();
BindDL();
}
private void BindDL() {
DataRow dr;
//取数据,具体代码中可以取自数据库
DataTable dt = new DataTable();
for (int i = 0; i < Convert.ToInt16(Label1.Text); i++)
{
dr = dt.NewRow();
dt.Rows.Add(dr);
}
DataList1.DataSource = dt;
DataList1.DataBind();
}
protected void Button1_Click(object sender, EventArgs e)
{
Button c = sender as Button;
DataListItem di = c.NamingContainer as DataListItem;
Label2.Text = "你按的是第" + (di.ItemIndex+1).ToString() +"个按钮!";
}
} --------------------编程问答-------------------- 新建个Default2.aspx
把前台和后台代码粘过去可以直接用。
补充:.NET技术 , ASP.NET