gridview绑定问题 数据库GRIDVIEW:正式工 派遣工数据绑定 数据绑定在数据库中(GH)E开始为正式工 A,B为派遣工怎么将正式工与派遣工总的数据绑定在gridview中,只要求总数就可以了。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 count(*) 两个表有关联关系就好了 一条SQL语句查询出需要的数据,然后绑定GridView即可select sum(case when left(gh,1)='E' then 1 else 0 end) as 正式工,sum(case when left(gh,1)='A' or left(gh,1)='B' then 1 else 0 end) as 派遣工 from Employees; <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %><!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"> <div> <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false"> <Columns> <asp:TemplateField HeaderText="序号"> <ItemTemplate> <%#Container.DataItemIndex+1 %> </ItemTemplate> </asp:TemplateField> <asp:BoundField DataField="正式工" HeaderText="正式工" ReadOnly="True" /> <asp:BoundField DataField="派遣工" HeaderText="派遣工" ReadOnly="True" /> </Columns> </asp:GridView> </div> </form></body></html>using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using System.Data;using System.Data.SqlClient;public partial class _Default : System.Web.UI.Page{ protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { BindGridView(); } } /// <summary> /// 绑定数据 /// </summary> public void BindGridView() { DataSet ds = new DataSet(); using (SqlConnection con = new SqlConnection("Data Source=localhost;uid=sa;pwd=111111;Database=CSDN")) { con.Open(); string strSQL = "select sum(case when left(gh,1)='E' then 1 else 0 end) as 正式工,sum(case when left(gh,1)='A' or left(gh,1)='B' then 1 else 0 end) as 派遣工 from Employees"; using (SqlDataAdapter adapter = new SqlDataAdapter(strSQL, con)) { adapter.Fill(ds); } } this.GridView1.DataSource = ds; this.GridView1.DataBind(); }} 用repeater怎么实现二级菜单 添加到收藏夹javascript脚本出错 为什么用了authentication后无法显示背景图片? ASP.NET网站配置管理的问题 是不是系統的iss問題阿? 缺少程序集引用 100分在线等待关于Cookie.Domain的用法? 很奇怪的SQL连接问题 进入微软的要求 紧急救助绑定Datagrid控件 asp.net调用vc写的com组件 如何获取值 怎么理解持久层?
sum(case when left(gh,1)='A' or left(gh,1)='B' then 1 else 0 end) as 派遣工
from Employees; <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %><!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">
<div>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:TemplateField HeaderText="序号">
<ItemTemplate>
<%#Container.DataItemIndex+1 %>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="正式工" HeaderText="正式工" ReadOnly="True" />
<asp:BoundField DataField="派遣工" HeaderText="派遣工" ReadOnly="True" />
</Columns>
</asp:GridView>
</div>
</form>
</body>
</html>using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindGridView();
}
} /// <summary>
/// 绑定数据
/// </summary>
public void BindGridView()
{
DataSet ds = new DataSet();
using (SqlConnection con = new SqlConnection("Data Source=localhost;uid=sa;pwd=111111;Database=CSDN"))
{
con.Open();
string strSQL = "select sum(case when left(gh,1)='E' then 1 else 0 end) as 正式工,sum(case when left(gh,1)='A' or left(gh,1)='B' then 1 else 0 end) as 派遣工 from Employees";
using (SqlDataAdapter adapter = new SqlDataAdapter(strSQL, con))
{
adapter.Fill(ds);
}
}
this.GridView1.DataSource = ds;
this.GridView1.DataBind();
}
}