<a href="http://www.baidu.com" onclick="alert('aa');return false;">gogog</a>
.net cs文件的判断提示
if (recontent.Length < 10 || recontent.Length > 2000) { Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "ok", "alert('内容长度应在10-2000字符之间');", true); return; }
一般用于删除后的提示
Response.Write("<script>alert('删除成功');window.location.replace('" + Request.Url.ToString() + "');</script>");
Repeater里面绑定Repeater方法
protected void RepeaterBankuai_ItemDataBound(object sender, RepeaterItemEventArgs e) { if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { //绑定最新的7条新闻 sqlcmd = "select top 7 tid,subject from bbssubject where online=1 and fid=" + fid + " order by huifu desc"; DataView dvlist = Bangso.DBUtility.SQLHelper.ExecuteDataview(sqlcmd); Repeater rep = e.Item.FindControl("Repeaterlist") as Repeater; rep.DataSource = dvlist; rep.DataBind(); } }
绑定DropDownList
string sqlcmd = string.Empty; sqlcmd = "select subject,fid from bbsClass order by PID"; DataView dv = Bangso.DBUtility.SQLHelper.ExecuteDataview(sqlcmd); DropDownList1.DataSource = dv; DropDownList1.DataTextField = "subject"; DropDownList1.DataValueField = "fid"; DropDownList1.DataBind();
ItemDataBound里常用的两种方法
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { Bangso.Module.Feeds dv = (Bangso.Module.Feeds)e.Item.DataItem; ((Literal)e.Item.FindControl("Literal1")).Text = dv.adate; } if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { DataRowView dv = ((DataRowView)e.Item.DataItem); ((Literal)e.Item.FindControl("Label1")).Text = dv.Row["adate"].ToString(); }
Repeater里绑定删除控件的常用方法
Repeater 里加onitemcommand事件 <asp:Repeater ID="Repeaterlist" runat="server" onitemcommand="Repeaterlist_ItemCommand"> 控件这样写 <asp:LinkButton ID="del" runat="server" CommandName="del" CommandArgument='<%#Eval("id") %>'>删除</asp:LinkButton> cs文件这样写 protected void Repeaterlist_ItemCommand(object source, RepeaterCommandEventArgs e) { if (e.CommandName == "del") { string loginusername = Bangso.MethodUtility.GetSession.getUsername(); string sqlcmd = string.Empty; sqlcmd = "delete from bbsShoucang where id =" + e.CommandArgument.ToString(); Bangso.DBUtility.SQLHelper.ExecuteNonQuery(sqlcmd); Response.Write("<script>alert('删除成功');window.location.replace('" + Request.Url.ToString() + "');</script>"); } }