GridView 使用方法总结
:
,aspx代码中是AllowSorting="True";
,如果要修改每页条数,修改PageSize即可,在aspx代码中是PageSize="12"。
,右击GridView弹出“属性”,选择AllowSorting为True即可。
,编辑,取消,删除:
后台代码:
你可以使用sqlhelper,本文没用。代码如下:
代码
using System;
using ;
using ;
using ;
using ;
using ;
using ;
using ;
using ;
using ;
public partial class _Default :
{
//清清月儿http://blog./
SqlConnection sqlcon;
mand ;
string strCon = "Data Source=(local);Database=数据库名;Uid=帐号;Pwd=密码";
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
bind();
}
}
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
= ;
bind();
}
//删除
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
string sqlstr = "delete from 表 where id='" + [].() + "'";
sqlcon = new SqlConnection(strCon);
= new mand(sqlstr,sqlcon);
();
.ExecuteNonQuery();
();
bind();
}
//更新
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
sqlcon = new SqlConnection(strCon);
string sqlstr = "update 表 set 字段1='"
+ ((TextBox)([].Cells[1].Controls[0])).().Trim() + "',字段2='"
+ ((TextBox)([].Cells[2].Controls[0])).().Trim() + "',字段3='"
+ ((TextBox)([].Cells[3].Controls[0])).().Trim() + "' where id='"
+ [].
详解GridView 使用方法 来自淘豆网www.taodocs.com转载请标明出处.