我想控制DataList输出表格,每列数据输出在一列表格,每行数据输出在一行。然后统计要出查询的数据列pay_num的和。应该怎么改呢?现在的代码是直接输出数据没有表格。<form id="form1" runat="server">
<div style="width: 746px; height: 299px;">
<asp:Label ID="gzh" runat="server" Text="输入查询活动期次:"></asp:Label>
<asp:TextBox ID="qc" runat="server"></asp:TextBox>
<asp:Label ID="spm" runat="server" Text="输入查询奖品编码:"></asp:Label>
<asp:TextBox ID="sp" runat="server"></asp:TextBox>
赠奖类型:<asp:DropDownList ID="lb" runat="server">
</asp:DropDownList>
开始日期:<input id="ksrq" runat="server" type="text" onclick="WdatePicker()"/>
截止日期:<input id="jzrq" runat="server" type="text" onclick="WdatePicker()"/>
<script language="javascript" type="text/javascript" src="My97DatePicker/WdatePicker.js"></script>
<asp:Button ID="Button1" runat="server" Text="赠奖情况查询" onclick="Button1_Click" />
<asp:DataList ID="cxkj" runat="server">
<ItemTemplate><%# Eval("pay_sp_name") %><%# Eval("input_name") %><%# Eval("input_data") %><%# Eval("pay_num") %><%# Eval("input_name") %></ItemTemplate>
</asp:DataList>
</div>
</form>
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["conn"]);
string cx_qc = qc.Text.Replace("+","");
string cx_sp = sp.Text.Replace("+","");
string ks = ksrq.Value.Replace("-","");
string jz = jzrq.Value.Replace("-","");
string zjlb = lb.SelectedValue;
string sql = "select * from zj_leiji_mingxi where input_date between '"+ks+"' and '"+jz+"'and qici='"+cx_qc+"' and pay_sp_bm='"+cx_sp+"' and leibie='"+zjlb+"'";
SqlCommand command = new SqlCommand(sql, conn);
command.CommandTimeout = 50;
SqlDataAdapter adp = new SqlDataAdapter();
adp.SelectCommand = command;
conn.Open();
DataSet ds = new DataSet();
adp.Fill(ds,"xs");
this.cxkj.DataSource = ds;
this.cxkj.DataBind();
}
<div style="width: 746px; height: 299px;">
<asp:Label ID="gzh" runat="server" Text="输入查询活动期次:"></asp:Label>
<asp:TextBox ID="qc" runat="server"></asp:TextBox>
<asp:Label ID="spm" runat="server" Text="输入查询奖品编码:"></asp:Label>
<asp:TextBox ID="sp" runat="server"></asp:TextBox>
赠奖类型:<asp:DropDownList ID="lb" runat="server">
</asp:DropDownList>
开始日期:<input id="ksrq" runat="server" type="text" onclick="WdatePicker()"/>
截止日期:<input id="jzrq" runat="server" type="text" onclick="WdatePicker()"/>
<script language="javascript" type="text/javascript" src="My97DatePicker/WdatePicker.js"></script>
<asp:Button ID="Button1" runat="server" Text="赠奖情况查询" onclick="Button1_Click" />
<asp:DataList ID="cxkj" runat="server">
<ItemTemplate><%# Eval("pay_sp_name") %><%# Eval("input_name") %><%# Eval("input_data") %><%# Eval("pay_num") %><%# Eval("input_name") %></ItemTemplate>
</asp:DataList>
</div>
</form>
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["conn"]);
string cx_qc = qc.Text.Replace("+","");
string cx_sp = sp.Text.Replace("+","");
string ks = ksrq.Value.Replace("-","");
string jz = jzrq.Value.Replace("-","");
string zjlb = lb.SelectedValue;
string sql = "select * from zj_leiji_mingxi where input_date between '"+ks+"' and '"+jz+"'and qici='"+cx_qc+"' and pay_sp_bm='"+cx_sp+"' and leibie='"+zjlb+"'";
SqlCommand command = new SqlCommand(sql, conn);
command.CommandTimeout = 50;
SqlDataAdapter adp = new SqlDataAdapter();
adp.SelectCommand = command;
conn.Open();
DataSet ds = new DataSet();
adp.Fill(ds,"xs");
this.cxkj.DataSource = ds;
this.cxkj.DataBind();
}
<DataList>
<AlternatingItemStyle />
<ItemTemplate>
<table>
<tr>
<td> </td>
</tr>
</table>
</ItemTemplate>
</DataList>
在数据源求和datatable.Compute("sum(pay_num)","")
<% if (dataList==null || dataList.count <1){%
<table >
<tr> <td>名称 </td> </tr>
<tr> <td>没有数据 </td> </tr>
</table>
<%}%>
<table >
<tr> <td>名称 </td> </tr>
<tr> <td>没有数据 </td> </tr>
</table>
<%}%>是不是 错了 ? 提示说 应输入:";"
前台代码如下: <asp:DataList ID="cxkj" runat="server" DataSourceID="ObjectDataSource1"
onitemdatabound="cxkj_ItemDataBound">
<HeaderTemplate>
<table cellpadding="0" cellspacing="0" border="1" width="100%" >
</HeaderTemplate>
<ItemTemplate>
<tr>
<td ><%# Eval("pay_sp_name") %></td><td ><%# Eval("input_name")%></td><td ><%# Eval("input_data")%></td><td ><asp:Label ID="Label1" runat="server" Text='<%# Eval("pay_num")%>'></asp:Label></td><td ><%# Eval("input_name")%></td>
</tr>
</ItemTemplate>
<FooterTemplate>
<tr>
<td > </td><td ></td><td ></td><td ><asp:Label ID="Label2" runat="server" Text="Label"></asp:Label></td><td ></td>
</tr>
</table>
</FooterTemplate>
</asp:DataList>后台累加,放在DataList的ItemDataBound事件中
int s = 0;
protected void cxkj_ItemDataBound(object sender, DataListItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
s += Convert.ToInt32(((Label)e.Item.FindControl("Label1")).Text); if (e.Item.ItemType == ListItemType.Footer)
((Label)e.Item.FindControl("Label2")).Text = s.ToString();
}