分类信息整站教材笔记

Data.Admin da=new Data.Admin(); //Data和Admin都是类

admin文件夹下添加web.config文件,匿名用户不能访问:

<authentication mode="Forms">

<deny users="?"/>

</autentication>

public DataSet getDataByID(int id)

{

cmd=new SqlCommand("select * from users where id=@id",conn);

cmd.Parameters.AddWithValue("@id",id);

da=new SqlDataAdapter(cmd);

ds=new DataSet();

da.Fill(ds);

return ds;

}

ObjectDataSource1.SelectParameters.Clear();

if(DropDownList1.SelectedIndex>0)

{

ObjectDataSource1.SelectedMethod="getDataByClassID";

ObjectDataSource1.SelectParameters.Add(new Parameter("clsid",TypeCode.Int32,DropDownList1.SelectedValue));

}

else

{

ObjectDataSource1.SelectedMethod="getData";

}

$chk()  检查元素是否存在

int id=0;

Int32.TryParse(Request["classid"],out id);  //尝试将id转换为整数,转换失败则id的值为0,此方法可以防止sql注入;

使用out和ref关键字可以使值参数按引用传递。

一般处理程序中:HttpRequest req=context.Request;

if(context.User.Identtity.IsAutherticated)  //判断是否通过登录验证

一般处理程序中用到session:

1.引入命名空间 using System.Web.SessionState;

2.继承IReadOnlySessionState接口  public class add:IHttpHandler,IReadOnlySessionState

3.context.Session["code"]

var postArgs=$('form1').toQueryString();    //表单form1中要提交的数据

index.js

mootools.js

$相当于Document.getElementById

//为登录用户提供身份验证票证

<asp:CheckBox ID="CheckBox1" runat="server" Text="记住登录" />

FormsAuthentication.SetAuthCookie(user, CheckBox1.Checked);

//指定登陆默认跳转的页面

<authentication mode="Forms" >

        <forms loginUrl="login.aspx" protection="All"></forms>

</authentication>

//读写流

string tempPath = HttpContext.Current.Server.MapPath(_tempPath);

System.IO.StreamReader sr = new System.IO.StreamReader(_head, System.Text.Encoding.Default);

string head = sr.ReadToEnd();

System.IO.StreamWriter sw= new System.IO.StreamWriter(saveFile, false, System.Text.Encoding.Default);

sw.Write(html);

//如果文件夹不存在,则创建文件夹

string p = HttpContext.Current.Server.MapPath(_descPath);

if (!System.IO.Directory.Exists(p)) System.IO.Directory.CreateDirectory(p);

无刷新分页:HTML+JS+ashx

菜单:输出HTML字符串

类文件(.cs)中用:HttpContext.Current.Server.MapPath();

一般处理程序(.ashx)中用:context.Server.MapPath(); HttpRequest req=context.Request;

Dreamweaver 修改 页面属性  标题、编码

StreamReader()两个参数,StreamWrite()三个参数。

//隐藏IP后几位

public static string HideIP(string s, int n)

        {

            string s1 = "";

            if (n >= 4)

            {

                s1 = "不显示";

            }

            else

            {

                string[] ip = s.Split('.');

                for (int i = 0; i < 4 - n; i++)

                {

                    s1 += ip[i] + ".";

                }

                s1 += "*";

            }

            return s1;

        }

//内容中有http:字符的,转换为超链接

        public static string AutoLink(string str)

        {

            string strContent = " " + str;

            Regex urlregex = new Regex(@"(http:\/\/([\w.]+\/?)\S*)", RegexOptions.IgnoreCase |  RegexOptions.Compiled);

            strContent = urlregex.Replace(strContent, "<a href=\"$1\" target=\"_blank\">$1</a>");

            Regex emailregex = new Regex(@"([a-zA-Z_0-9.-]+\@[a-zA-Z_0-9.-]+\.\w+)",

            RegexOptions.IgnoreCase | RegexOptions.Compiled);

            strContent = emailregex.Replace(strContent, "<a href=mailto:$1>$1</a>");

            return strContent;

        }

自定义绑定  代码表达式:Eval("id")

模板列中添加LinkButton,设置CommandArgument,CommandName属性

protected void GridView1_RowCommand(object sender,GridViewCommandEventArgs e)

{

if(e.CommandName=="...")

{

int id=Int32.Parse(e.CommandArgument.ToString());

...

LindButton lb=(linkButton)e.CommandSource;

if(lb!=null) lb.Enabled=false;

}

}

原文地址:https://www.cnblogs.com/cw_volcano/p/1947523.html