asp.net 学习笔记(1)

来源:互联网 发布:企业ip网络设计拓扑 编辑:程序博客网 时间:2024/05/21 17:01
 

1.输出提示框,不改变html布局:

  ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script>alert('插入备忘录的主题,不能超过50个字符!');</script>");

2.   Response.Redirect("addessay.aspx?title=" + this.Lbtitle.Text +"&state="+editstate+"");

传参数的时候,特别注意红色衔接处不要有空格,否则参数接收时接收不到。

接收: State=Request.QueryString["state"];(vs2010 中中英文参数都可以接收)     ++里边的值必须存在,可以现编写。

3.sql增删改查语句:

 string insertSql = "insert into tb_memo(subject,alertTime) values('" + this.TxtSubject.Text + "','" + this.Label2.Text + "')";

 

   string strdel = "delete from essay where title= '" + this.Lbtitle.Text + "'";

 

 strInsert = "update essay set textcontent='" + strContent + "',pubtime='" + time + "' where title='" + strTitle + "'  ";

 

"select count(*) from person where pID='";

4.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script>alert('文章修改完成。');</script>");
            Response.Redirect("essy.aspx");

为何不输出提示,直接跳转到其他页面?

5.要让datalist显示时选定第一个,把selectedindex 设置为0(默认为-1);

6.datalist 绑定图片

 <ItemTemplate>
                <img src='images/<%#DataBinder.Eval(Container.DataItem, "pname")%>' height="120" width="150" border="5" border-color="white">
                </ItemTemplate>

6.获得记录数

 SqlDataAdapter objCommand = new SqlDataAdapter("select * from photodetail where pID='" + ID + "'", con);
        DataSet ds = new DataSet();
        objCommand.Fill(ds);
        if (ds.Tables[0].Rows.Count == 0)
        {
            this.lbmess.Text = "该相册还没有照片马上添加吧!!";  
        }

7.dataview 控件的绑定

SqlConnection con = DB.createConnection();
                con.Open();
                SqlCommand cmd = new SqlCommand("select * from pet", con);
                SqlDataReader sdr = cmd.ExecuteReader();
                this.GridView1.DataSource = sdr;
                this.GridView1.DataBind();

原创粉丝点击