今天主要内容:
1. GridView的分页(2种方法)
a) 内置分页
b) 存储过程分页
2. GridView的排序
3. GridView的全选和全不选
存储分页 局部代码:
string str1 = System.Configuration.ConfigurationManager.ConnectionStrings["<connectionStrings>"].ConnectionString;
using (SqlConnection sqlcnn = new SqlConnection(str1))
{
SqlCommand sqlcmm = sqlcnn.CreateCommand();
sqlcmm.CommandText = "存储过程";
sqlcmm.CommandType = System.Data.CommandType.StoredProcedure;
sqlcmm.Parameters.Add("@pageSize", 1);
sqlcmm.Parameters.Add("@pageCount", SqlDbType.Int).Direction = ParameterDirection.Output;
sqlcmm.Parameters.AddWithValue("@pageIndex",PageIndex);
SqlDataAdapter da = new SqlDataAdapter(sqlcmm);
DataSet ds = new DataSet();
da.Fill(ds);
this.GridView1.DataSource = ds.Tables[0];
this.GridView1.DataBind();
this.HiddenField1.Value = PageIndex.ToString();
this.HiddenField2.Value = sqlcmm.Parameters["@pageCount"].Value.ToString();
this.Label1.Text = PageIndex + "/" + this.HiddenField2.Value;
}
全选和不选
<script type="text/javascript">
function change(sender) {
var table = document.getElementById("GridView1");
for (var i = 1; i < table.rows.length; i++) {
table.rows[i].cells[0].getElementsByTagName("input")[0].checked = sender.checked;
}
}</script>
<input id="Checkbox3" type="checkbox" οnclick="change(this)" /> //为服务器着想