这个功能我实现过 这是 我的代码
后台代码:
using System
using System.Data
using System.Configuration
using System.Web
using System.Web.Security
using System.Web.UI
using System.Web.UI.WebControls
using System.Web.UI.WebControls.WebParts
using System.Web.UI.HtmlControls
using System.Data.SqlClient
public partial class Default5 : System.Web.UI.Page
{
SqlConnection sqlcon
string strCon = "Data Source=(local)Database=北风贸易Uid=saPwd=sa"
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
bind()
}
}
protected void CheckBox2_CheckedChanged(object sender, EventArgs e)
{
for (int i = 0 i <= GridView1.Rows.Count - 1 i++)
{
CheckBox cbox = (CheckBox)GridView1.Rows[i].FindControl("CheckBox1")
if (CheckBox2.Checked == true)
{
cbox.Checked = true
}
else
{
cbox.Checked = false
}
}
}
protected void Button2_Click(object sender, EventArgs e)
{
sqlcon = new SqlConnection(strCon)
SqlCommand sqlcom
for (int i = 0 i <= GridView1.Rows.Count - 1 i++)
{
CheckBox cbox = (CheckBox)GridView1.Rows[i].FindControl("CheckBox1")
if (cbox.Checked == true)
{
string sqlstr = "delete from where 身份z号码='" + GridView1.DataKeys[i].Value + "'"
sqlcom = new SqlCommand(sqlstr, sqlcon)
sqlcon.Open()
sqlcom.ExecuteNonQuery()
sqlcon.Close()
}
}
bind()
}
protected void Button1_Click(object sender, EventArgs e)
{
CheckBox2.Checked = false
for (int i = 0 i <= GridView1.Rows.Count - 1 i++)
{
CheckBox cbox = (CheckBox)GridView1.Rows[i].FindControl("CheckBox1")
cbox.Checked = false
}
}
public void bind()
{
string sqlstr = "select top 5 * from "
sqlcon = new SqlConnection(strCon)
SqlDataAdapter myda = new SqlDataAdapter(sqlstr, sqlcon)
DataSet myds = new DataSet()
sqlcon.Open()
myda.Fill(myds, "tb_Member")
GridView1.DataSource = myds
GridView1.DataKeyNames = new string[] { "身份z号码" }
GridView1.DataBind()
sqlcon.Close()
}
}
前台主要代码:
<asp:GridView ID="GridView1" runat="server" AllowSorting="True" AutoGenerateColumns="False"
CellPadding="3" Font-Size="9pt" BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px">
<FooterStyle BackColor="White" ForeColor="#000066" />
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="身份z号码" HeaderText="用户ID" SortExpression="身份z号码" />
<asp:BoundField DataField="姓名" HeaderText="用户姓名" SortExpression="姓名"/>
<asp:BoundField DataField="家庭住址" HeaderText="家庭住址" SortExpression="家庭住址"/>
</Columns>
<RowStyle ForeColor="#000066" />
<SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left" />
<HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" />
</asp:GridView>
<asp:CheckBox ID="CheckBox2" runat="server" AutoPostBack="True" Font-Size="9pt" OnCheckedChanged="CheckBox2_CheckedChanged"
Text="全选" />
<asp:Button ID="Button1" runat="server" Font-Size="9pt" Text="取消" OnClick="Button1_Click" />
<asp:Button ID="Button2" runat="server" Font-Size="9pt" Text="删除" OnClick="Button2_Click" />
查询时加序号a:没有主键的情形:
Select identity(int,1,1) as iid,* into #tmp from TableName
Select * from #tmp
Drop table #tmp
b:有主键的情形:
Select (Select sum(1) from TableName where KeyField <= a.KeyField) as iid,* from TableName a
eg:
select (select sum(1) from user_Admin where id<=a.id) as ID,id,displayName from user_Admin a order by a.ID asc
结果:
------------------------------------------------------------
USE 北风贸易
GO
/* 方法一*/
SELECT 序号= (SELECT COUNT(客户编号) FROM 客户 AS LiMing
WHERE LiMing.客户编号<= Chang.客户编号),
客户编号, 公司名称
FROM 客户 AS Chang ORDER BY 1
GO
/* 方法二: 使用SQL Server 2005 独有的RANK() OVER () 语法*/
SELECT RANK() OVER (ORDER BY 客户编号 DESC) AS 序号,
客户编号, 公司名称
FROM 客户
GO
/* 方法三*/
SELECT 序号= COUNT(*), LiMing.客户编号, LiMing.公司名称
FROM 客户 AS LiMing, 客户AS Chang
WHERE LiMing.客户编号>= Chang.客户编号
GROUP BY LiMing.客户编号, LiMing.公司名称
ORDER BY 序号
GO
/* 方法四
建立一个「自动编号」的字段,然后将数据新增至一个区域性暂存数据表,
然后由该区域性暂存数据表中,将数据选取出来,最后删除该区域性暂存数据表
*/
SELECT 序号= IDENTITY(INT,1,1), 管道, 程序语言, 讲师, 资历
INTO #LiMing
FROM 问券调查一
GO
SELECT * FROM #LiMing
GO
DROP TABLE #LiMing
GO
/*
方法五
使用 SQL Server 2005 独有的ROW_NUMBER() OVER () 语法
搭配 CTE (一般数据表表达式,就是 WITH 那段语法)选取序号2 ~ 4 的数据
*/
WITH 排序后的图书 AS
(SELECT ROW_NUMBER() OVER (ORDER BY 客户编号 DESC) AS 序号,
客户编号, 公司名称
FROM 客户)
SELECT * FROM 排序后的图书
WHERE 序号 BETWEEN 2 AND 4
GO
------------分页使用---------------------------
SELECT RANK() OVER (ORDER BY id asc) AS no,* into #temp
FROM Bbs_reply select * from #temp where no between 1 and 100 drop table #temp
参考 3.我啊,只想安稳地做个忍者,安稳地生活,和一个不美也不丑的女人安稳地结婚,安稳地生两个小孩,第一个是女孩,之后是男孩。等女儿结了婚,儿子独立后便退休,之后闲时和朋友下下象棋或围棋,过着悠哉悠哉的隐居生活,然后先太太一步离开这个世界,能有这种人生就好了。————鹿丸-欢迎分享,转载请注明来源:内存溢出
评论列表(0条)