时间:2016-02-16 00:54 来源: 我爱IT技术网 作者:佚名
欢迎您访问我爱IT技术网,今天小编为你分享的编程技术是:【Datalist控件使用存储过程来分页实现代码】,下面是详细的讲解!
Datalist控件使用存储过程来分页实现代码
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
bindProduct(1);
}
}
private void bindProduct(int pageIndex)
{
string constr=ConfigurationManager.ConnectionStrings["studentConnectionString"].ConnectionString;
using (SqlConnection con=new SqlConnection(constr))
{
con.Open();
using (SqlCommand cmd=con.CreateCommand())
{
cmd.CommandType=CommandType.StoredProcedure;
cmd.CommandText="sp_Product_Select_by_Page_rowNumber";
cmd.Parameters.AddWithValue("@pageSize", 3);
cmd.Parameters.Add("@pageCount", System.Data.DbType.Int32).Direction=ParameterDirection.Output;
cmd.Parameters.AddWithValue("@pageIndex", pageIndex);
SqlDataAdapter adapter=new SqlDataAdapter(cmd);
DataTable dt=new DataTable();
adapter.Fill(dt);
this.DataList1.DataSource=dt;
this.DataList1.DataBind();
int pageCount=Convert.ToInt32(cmd.Parameters["@pageCount"].Value);
this.HiddenField1.Value=pageCount.ToString();
this.HiddenField2.Value=pageIndex.ToString();
}
}
}
protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
{
if (e.CommandName=="Buy")
{
Response.Write(e.CommandArgument.ToString());
}
}
protected void DataList1_EditCommand(object source, DataListCommandEventArgs e)
{
this.DataList1.EditItemIndex=e.Item.ItemIndex;
this.bindProduct(1);
}
protected void DataList1_UpdateCommand(object source, DataListCommandEventArgs e)
{
string ProName=(e.Item.FindControl("txtProductName") as TextBox).Text;
string ProStandarde=(e.Item.FindControl("txtProductStandard") as TextBox).Text;
string ProPackaging=(e.Item.FindControl("txtPackagingRatio") as TextBox).Text;
string ProArtialeNum=(e.Item.FindControl("txtArticleNum") as TextBox).Text;
string ProPrice=(e.Item.FindControl("txtPrice") as TextBox).Text;
string sql="update Product set ProductName=@ProductName,ProductStandard=@ProductStandard,PackagingRatio=@PackagingRatio,ArticleNum=@ArticleNum,Price=@Price where PId=@pid";
SqlParameter[] pms=new SqlParameter[]{
new SqlParameter("@ProductName",ProName),
new SqlParameter("@ProductStandard",ProStandarde),
new SqlParameter("@PackagingRatio",ProPackaging),
new SqlParameter("@ArticleNum",ProArtialeNum),
new SqlParameter("@Price",ProPrice),
new SqlParameter("@pid",e.CommandArgument)
};
SQLHelper.ExecuteNonQuery(sql, pms);
}
protected void DataList1_CancelCommand(object source, DataListCommandEventArgs e)
{
this.DataList1.EditItemIndex=-1;
this.bindProduct(1);
}
protected void DataList1_DeleteCommand(object source, DataListCommandEventArgs e)
{
string sql="delete from Product where PId=@pid";
SqlParameter pms=new SqlParameter("@pid", e.CommandArgument);
SQLHelper.ExecuteNonQuery(sql, pms);
this.bindProduct(1);
}
protected void btnFirst_Click(object sender, EventArgs e)
{
this.bindProduct(1);
}
protected void btnPrev_Click(object sender, EventArgs e)
{
int index=Convert.ToInt32(this.HiddenField2.Value);
if (index > 1)
{
index--;
this.bindProduct(index);
}
}
protected void btnNext_Click(object sender, EventArgs e)
{
int index=Convert.ToInt32(this.HiddenField2.Value);
int pageCount=Convert.ToInt32(this.HiddenField1.Value);
if (index<pageCount)
{
index++;
this.bindProduct(index);
}
}
protected void btnLast_Click(object sender, EventArgs e)
{
this.bindProduct(Convert.ToInt32(this.HiddenField1.Value));
}
protected void btnGo_Click(object sender, EventArgs e)
{
if (Convert.ToInt32(txtPageNumber.Text) <=Convert.ToInt32(HiddenField1.Value))
{
this.bindProduct(Convert.ToInt32(txtPageNumber.Text));
}
else
{
Response.Write("您输入的页数超出了总页数,如有需要请重新输入!");
}
}
protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
{
Label1.Text="第" + (HiddenField2.Value).ToString() + "页,共" + HiddenField1.Value.ToString() + "页";
}
关于Datalist控件使用存储过程来分页实现代码的用户互动如下:
相关问题:
答: >>详细
相关问题:
答: >>详细
相关问题:
答: >>详细
- 【asp】asp.net url重写浅谈-net-url重写
- 【DataSet】DataSet、DataTable、DataRow区别详解
- 【asp】asp.net 动态添加多个用户控件-net-动态添
- 【ASP】ASP.NET中内嵌页面代码的一个问题-NET-内
- 【As】Asp.net中的页面乱码的问题-sp--pn-ne-et
- 【增加记录】asp.net中获取新增加记录的ID Access
- 【创建】ASP.NET Web API教程 创建域模型的方法详
- 【Asp】Asp.net 页面调用javascript变量的值-net-
- 【ASP】ASP.NET 5升级后如何删除旧版本的DNX-NET5
- 【404页面】ASP.NET设置404页面返回302HTTP状态码
- 评论列表(网友评论仅供网友表达个人看法,并不表明本站同意其观点或证实其描述)
-
