ASP.NET中repeater控件如何使用-创新互联
ASP.NET中repeater控件如何使用,很多新手对此不是很清楚,为了帮助大家解决这个难题,下面小编将为大家详细讲解,有这方面需求的人可以来学习下,希望你能有所收获。
成都创新互联是专业的舟山网站建设公司,舟山接单;提供成都网站设计、做网站,网页设计,网站设计,建网站,PHP网站建设等专业做网站服务;采用PHP框架,可快速的进行舟山网站开发网页制作和功能扩展;专业做搜索引擎喜爱的网站,专业的做网站团队,希望更多企业前来合作!repeater绑定数据:
protected void Page_Load(object sender, EventArgs e) { if(!IsPostBack) BindStudent();} private void BindStudent(){ string str = ConfigurationManager.ConnectionStrings["stucnn"].ConnectionString; using (SqlConnection sqlCnn = new SqlConnection(str)) { using (SqlDataAdapter da = new SqlDataAdapter("select * from student", sqlCnn)) { DataSet ds = new DataSet(); da.Fill(ds); this.Repeater1.DataSource = ds; this.Repeater1.DataBind(); } }}
删除数据:
protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e) { if (e.CommandName == "Delete") { string str = ConfigurationManager.ConnectionStrings["stucnn"].ConnectionString; using (SqlConnection sqlCnn = new SqlConnection(str)) { using (SqlCommand sqlCmm = sqlCnn.CreateCommand()) { sqlCnn.Open(); sqlCmm.CommandText = "delete from student where sid=" + e.CommandArgument.ToString(); sqlCmm.ExecuteNonQuery(); } } this.BindStudent(); } else if (e.CommandName == "Edit") { Server.Transfer("Edit.aspx?sid=" + e.CommandArgument.ToString()); } }
前台:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
启用,禁用:
protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e){ //string status = e.CommandName; if ((e.CommandName == "true")||(e.CommandName == "false")) { string str = ConfigurationManager.ConnectionStrings["stucnn"].ConnectionString; using (SqlConnection sqlCnn = new SqlConnection(str)) { using (SqlCommand sqlCmm = sqlCnn.CreateCommand()) { sqlCnn.Open(); sqlCmm.CommandText = "update student set status=@status where sid=" + e.CommandArgument.ToString(); sqlCmm.Parameters.AddWithValue("@status",e.CommandName); sqlCmm.ExecuteNonQuery(); } } this.BindStudent(); }} <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Debug="true" Inherits="Default2" %>
看完上述内容是否对您有帮助呢?如果还想对相关知识有进一步的了解或阅读更多相关文章,请关注创新互联行业资讯频道,感谢您对创新互联网站建设公司,的支持。
文章标题:ASP.NET中repeater控件如何使用-创新互联
浏览地址:http://myzitong.com/article/doohde.html