asp.net repeater 后台动态添加行
一个纳税记录列表,用repeater循环绑定,现在根据客户、年份和月份为条件,添加一行,总结对应客户该月的纳税额总数,如图所示,红色方框内的为动态添加的行,和相应的显示数...
一个纳税记录列表,用repeater循环绑定,现在根据客户、年份和月份为条件,添加一行,总结对应客户该月的纳税额总数,如图所示,红色方框内的为动态添加的行,和相应的显示数据,这种效果该如何实现,求大神指教
展开
展开全部
想实现这个效果,你的前台页面需要添加一列,空列
<table>
<tr>
<th>编号</th>
...
<th></th><!--添加这一列,用来显示纳税总数-->
</tr>
</table>
后台代码
//这是你现在有的数据源
List<T> list = new List<T>();
//整理数据源(你应该是根据用户年份分组,我这么理解的。这里就要看你自己怎么整理你的数据)
var query = (from c in list
group c by new {c.xxx,c.yyy} into g
select new T{xxx=xxx,yyy=yyy}).ToList<T>();
//现在原来的数据源有了;需要添加的新的一列的数据源也有的。
//将两个数据远,整合成一个。(这里要注意,数据源整合时,数据的位置)
//最后一步是绑定
展开全部
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="repeater获取控件.aspx.cs" Inherits="repeater获取控件" %>
<!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>test</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1" OnItemCommand="Repeater1_ItemCommand"
>
<HeaderTemplate>
<table>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<asp:TextBox ID="TextBox1" runat="server" Text='<%#Eval("A") %>'></asp:TextBox>
</td>
<td>
<asp:Button ID="Button1" runat="server" Text="Button" CommandName="get" />
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:db_10ConnectionString3 %>"
SelectCommand="SELECT * FROM [test126]"></asp:SqlDataSource>
</div>
</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 repeater获取控件 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
{
if (e.CommandName.Equals("get"))
{
TextBox text = e.Item.FindControl("TextBox1") as TextBox;
Response.Write(text.Text);
}
}
}
<!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>test</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1" OnItemCommand="Repeater1_ItemCommand"
>
<HeaderTemplate>
<table>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<asp:TextBox ID="TextBox1" runat="server" Text='<%#Eval("A") %>'></asp:TextBox>
</td>
<td>
<asp:Button ID="Button1" runat="server" Text="Button" CommandName="get" />
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:db_10ConnectionString3 %>"
SelectCommand="SELECT * FROM [test126]"></asp:SqlDataSource>
</div>
</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 repeater获取控件 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
{
if (e.CommandName.Equals("get"))
{
TextBox text = e.Item.FindControl("TextBox1") as TextBox;
Response.Write(text.Text);
}
}
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询