asp tips

网络命令:netstat -a-n

1。在gridview里面选中删除一行。

GridView中添加一个模板列:LinkButton.设置CommandName="Delete"OnClientClick="return confirm('确认要删除吗?');"

Html
代码如下:



<asp:TemplateField HeaderText="
删除">
                                
<ItemTemplate>
                                    
<asp:LinkButton ID="LinkButton1" runat="server" CommandName="Delete" OnClientClick="return confirm('确认要删除吗?');">删除</asp:LinkButton>
                                
</ItemTemplate>
                            
</asp:TemplateField>


然后把删除代码写在RowDeleting事件中:

protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    
{
        
int j = Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Value);
        addb.DeleteADType(j);
        GridView1.DataSource = addb.GetAdType().Tables[0];
        GridView1.DataBind();
    }

2.连接数据库:

 SqlConnection sqlconn = new SqlConnection(ConfigurationSettings.AppSettings["connStringSelina"]);

3datalist中的数据绑定.

 <tr><td>留言人:<%# DataBinder.Eval(Container.DataItem,"Inputer")%></td></tr>

 <tr><td>留言时间:<%# DataBinder.Eval(Container.DataItem,"CreateTime")%></td></tr>

4.datalist中的传值绑定。

<a href="LMsg.aspx?ID=<%#DataBinder.Eval(Container.DataItem,"MId") %>">回复留言</a>

5.页面之间传值:

string url;

        url = "AddCardOK.aspx?OpenName=" + TxtOpenName.Text + "&kaihao=" + Txtcard.Text + "&cardType=" + DrLType.SelectedValue.ToString() + "&UsePid=" + TxtPid.Text + "&times=" + Txt_time.Value.ToString() + "&CardInperson=" + TxtInName.Text + "&IsOpen=" + DropDownList1.SelectedValue.ToString();

        Response.Redirect(url);

B页面中:label.text=request.querystring["变量名"]

6. 给一个提示:

 Response.Write("<script>alert('修改成功!'); </script>");

7.gridview 一行不可见;

 e.Row.Cells[5].Attributes.Add("style",   "display:none");  

8.显示客户端IP地址

 this.Label1.Text = "客户端IP地址"+Request.UserHostAddress;

9.调用用户控件

<%@ Register TagPrefix="uc1" TagName="Header1" Src="~/Controls/top.ascx" %>

10.调用CSS

<head runat="server">

    <title>论坛</title>

     <link href="../CSS/Normal.css" type="text/css" rel="stylesheet" />

</head>

11执行存储过程

            SqlConnection con = new SqlConnection(DB.GetConStr());

            con.Open();

            SqlCommand com = new SqlCommand("存储过程名称",con);

            com.CommandType = CommandType.StoredProcedure;

            SqlParameter sp = new SqlParameter("存储过程参数",SqlDbType.VarChar,50);

            sp.Value = userName.Text;

            com.Parameters.Add(sp);

           com.ExecuteNonQuery();

12.不成功,反加上一个步骤:

if (count > 0)

        {

            Response.Write("<script> alert('该用户名

已存在!);location='javascript:history.go(-1)'</script>");

        }

13.鼠标放到上面变色。 双击打开页面。 点击删除一行.

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)

    {

        if (e.Row.RowType == DataControlRowType.DataRow)

        {

            e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#E0E0E0';this.style.color='buttontext';this.style.cursor='default';");

            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#EFF3FB'");

            e.Row.Attributes.Add("ondblclick", "window.open('a.aspx?id=" + e.Row.Cells[1].Text + "')");   //双击打开页面

            ((LinkButton)e.Row.Cells[0].Controls[0]).Attributes.Add("onclick", "return confirm('确定删除?')");

        }

}

14.判断用户类型,查询所需的用户:

 

    public DataSet GetUserList(string GetType)

    {

        string selectString;

        selectString = "select u.UserID,u.UserName,u.UserEmail,u.TrueName,u.RegDate,u.LoginNum,u.LastLogin,t.Type from bbc_user as u inner join bbc_user_type as t on u.UserClass=t.ID";

        switch (GetType)

        {

            case null:

                selectString += "";

                break;

            case "commonuser":

                selectString += " where u.UserClass=1";

                break;

            case "gmuser":

                selectString += " where u.UserClass=2";

                break;

            case "CXTuser":

                selectString += " where u.UserClass=3";

                break;

            case "Login24h":

                selectString += " where u.LastLogin > '" + DateTime.Now.AddDays(-1).ToString() + "'";

                break;

            case "Reg24h":

                selectString += " where u.RegDate >'" + DateTime.Now.AddDays(-1).ToString() + "'";

                break;

            case "LockUser":

                selectString += " where u.LockUser=1";

                break;

        }

        selectString += " Order By u.UserID DESC";

        db.DBOpen();

        DataSet ds = db.FillDataSet(selectString);

        db.DBClose();

        return ds;

    }

 

 

 

 

15Gridview 里自定义分页:

<PagerSettings FirstPageText="首页" LastPageText="末页" Mode="NextPreviousFirstLast"

                         NextPageText="下一页" PreviousPageText="上一页" />

protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)

    {

        GridView1.PageIndex = e.NewPageIndex;

        this.GridView1.DataBind();

    }

16.Gridview 里设定他的的样式:

   <PagerStyle BackColor="#B12B00" HorizontalAlign="Center" ForeColor="White" />

                    <FooterStyle BackColor="#F43F00" Font-Bold="True" ForeColor="White" />

                    <RowStyle BackColor="#FFF0EA" />

                   <SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />

                    <HeaderStyle BackColor="#F43F00" Font-Bold="True" ForeColor="White" />

                    <EditRowStyle BackColor="#7C6F57" />

                    <AlternatingRowStyle BackColor="White" />

17GridView基本的操作 编辑 更新 取消

public partial class GridView_GridView_DeleteUpdate1 : System.Web.UI.Page
{
    Practice.DAL.authors authorsbll = 
new Practice.DAL.authors();

    
protected void Page_Load(object sender, EventArgs e)
    
{
        
if (!IsPostBack)
        
{
            DataBindGridView();
        }
        GridView1.RowDeleting += 
new GridViewDeleteEventHandler(GridView1_RowDeleting);
        GridView1.RowEditing += 
new GridViewEditEventHandler(GridView1_RowEditing);
        GridView1.RowCancelingEdit += 
new GridViewCancelEditEventHandler(GridView1_RowCancelingEdit);
        GridView1.RowUpdating += 
new GridViewUpdateEventHandler(GridView1_RowUpdating);
    }

    
/// <summary>
    
///     能:GridView删除事件
    
/// 作  者:PUKE
    
/// 完成时间:2007-05-18
    /// 版  权:pukesys@tom.com
    
/// </summary>
    
/// <param name="sender"></param>
    
/// <param name="e"></param>
    void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    
{
        
string id = GridView1.Rows[e.RowIndex].Cells[0].Text.Trim();

        authorsbll.Delete(id);
//删除,函数自己写

        DataBindGridView();
//重新绑定数据源
    }

    
/// <summary>
    
///     能:GridView编辑事件
    
/// 作  者:PUKE
    
/// 完成时间:2007-05-18
    /// 版  权:pukesys@tom.com
    
/// </summary>
    
/// <param name="sender"></param>
    
/// <param name="e"></param>
    void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
    
{
        GridView1.EditIndex = e.NewEditIndex;
        DataBindGridView();
    }

    
/// <summary>
    
///     能:GridView取消事件
    
/// 作  者:PUKE
    
/// 完成时间:2007-05-18
    /// 版  权:pukesys@tom.com
    
/// </summary>
    
/// <param name="sender"></param>
    
/// <param name="e"></param>
    void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
    
{
        GridView1.EditIndex = -1;
        DataBindGridView();
    }

    
/// <summary>
    
///     能:GridView更新事件
    
/// 作  者:PUKE
    
/// 完成时间:2007-05-18
    /// 版  权:pukesys@tom.com
    
/// </summary>
    
/// <param name="sender"></param>
    
/// <param name="e"></param>
    void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    
{
        
string aa = (((TextBox)(GridView1.Rows[e.RowIndex].Cells[0].Controls[0])).Text.ToString().Trim());
        GridView1.EditIndex = -1;
        DataBindGridView();
    }    

    
/// <summary>
    
///     能:绑定GridView
    
/// 作  者:PUKE
    
/// 完成时间:2007-05-18
    /// 版  权:pukesys@tom.com
    
/// </summary>
    private void DataBindGridView()
    
{
        DataSet ds = authorsbll.GetList("");
        GridView1.DataSource = ds;
        GridView1.DataBind();
    }
}

18.判断DataSet 里的记录集是否为空

if (myDataSet == null || myDataSet.Tables[0].Rows.Count == 0)
{
//
为空时进行处理
}
else
{
//
不为空时处理
}

19.选中日期:

protected void Calendar1_SelectionChanged(object sender, EventArgs e)

    {

        Response.Write(string.Format("选中的日期为{0}",Calendar1.SelectedDates[0].ToString("yyyy-MM-dd")));

}

20. LiteralLabel到底有什么区别,

其实它们也只有一个区别,就是在转换成客户端Html代码后,Label就成了<span></span>,Literal则是什么标记都不带

21.新建VS2005的调式根目录

1.工具---> 外部工具----->添加  

2.命令:C:"WINDOWS"Microsoft.NET"Framework"v2.0.50727"WebDev.WebServer.EXE

3.参数:/port:8080 /path:$(ProjectDir):

22.{0} {1} 等来接收参数.

public void UpdateAdminLoginLog(string FromIp, int AdminId)

        {

            db.DBOpen();

            string strSQL = string.Format("update bbc_admin set LastLogin='{0}' , LastLoginIP='{1}' , loginnum=loginnum+1 where adminID={2}", DateTime.Now, FromIp, AdminId);

            db.Execute(strSQL);

            db.DBClose();

        }

23.信息存入cookies

HttpCookie cookie = new HttpCookie["名称"];

cookie.Values.Add("webmaster","飞刀");
cookie.Values.Add("writer","beige");
cookie.Values.Add("LinkColor","blue");

24.读取cookies:

HttpCookie cookie = Request.Cookies["名称"];
value1 = cookies.Values["webmaster"];
value2 = cookies.Values["writer"];

25.      上传图片

protected void btnUpload_Click(object sender, EventArgs e)

    {

        //上传文件

        if (IsPostBack)

        {

            Boolean fileOK = false;

            String Path = Server.MapPath("~/UploadFiles/");

            String fileExtension = null;

            if (FileUpload1.HasFile)

            {

                fileExtension = System.IO.Path .GetExtension(FileUpload1.FileName).ToLower();

                String[] allowExtension = { ".jpg", ".jpeg", ".gif", ".png" };

                for (int i = 0; i < allowExtension.Length; i++)

                {

                    if (fileExtension == allowExtension[i])

                    {

                        fileOK = true;

                    }

                }

            }

            if (fileOK)

            {

                try

                {

                    String newfilename = Path + new PubFun().CreateRandomString() + fileExtension;

                    FileUpload1.PostedFile.SaveAs(newfilename);

                    tbphoto.Text = "/UploadFiles/" + newfilename.Replace(Path, null);

                }

                catch (Exception ex)

                {

                    tbphoto.Text = "文件上传出现错误,请检查重试";

                    Response.Write(ex);

                }

            }

            else

            {

                tbphoto.Text = "此类文件不允许上传";

            }

        }

}

26 request.params

request.params其实是一个集合,它依次包括request.querystring、request.form、request.cookies和request.servervariables

26.ViewState 

简而言之,ViewState是保存跨页面生命周期有关变量的最好容器,但它又不能够跨出页面范围真正符合其名称用来保存ViewState的。例如有GridAGridB两个页面,点击一个条目查看明细都回转到Details页面,同时Details页面要提供返回原来页面的途径

27.        DataFormatString="{0:格式字符串}"

28.巧妙的利用sql语句

select MID,case when MType='1' then '咨询' when MType='2' then '建议' else '投诉' end as MType,Inputer,Title,MContent,IsChecked,CreateTime,case when status='1' then '处理中...' when status='0' then '未处理' else '已处理' end as status from UMsg order by CreateTime ASC

28.    角本

<script language="javascript" type="text/javascript">

        oldDiv=null;

        function DivState(DivID){

            if(oldDiv!=null){

                oldDiv.style.display='none';

            }

            var IDiv=document.getElementById("Div"+DivID);

            IDiv.style.display='';

            readed (DivID);

            DivOld("Div"+DivID);

            top.leftFrame.location.reload();

        }

        function DivOld(oldID){

            oldDiv=document.getElementById(oldID);

        }

        function readed (ID){            //返回问题

             var ajax=new AJAXRequest;

             var d = new Date();

             ajax.post(

                  "sysreaded.aspx?d="+d.getTime(),

                  "NID="+ID,

                  function(obj) {return obj.responseText;}

                  );

         }

</script>

29.         刷新:

Response.Write("<script language=javascript>window.location.href=window.location.href;</script>");

30.单链接!

NavigateUrl   ='<%#   DataBinder.Eval(Container.DataItem,"GoodsID","productInfo.aspx?action={0})%>'/>

30.    捕获异常.并输出:

   catch(Exception    ex)   
   {   
   HttpContext.Current.Response.Write(ex.Message);   

31.       安装asp.net2.0框架

 C:/WINDOWS/Microsoft.NET/Framework/v2.0.50727/aspnet_regiis.exe -i

32.当连接sql server使用信任连接时就会出这个错误,在Windows XP当中,ASP.NET的运行帐号是ASPNET,而在Windows server 2003当中,运行帐号则改为了Network Service

33.一个网站的分网站的创建.

 IIS里面在你的那个项目的文件夹上面右键属性里面  
 
目录选项下面的  
 
应用程序名后面点击创建即可!

posted on 2008-04-01 12:09 lby 阅读(253) 评论(0)  编辑 收藏 引用

只有注册用户登录后才能发表评论。

导航

<2008年4月>
303112345
6789101112
13141516171819
20212223242526
27282930123
45678910

统计

常用链接

留言簿(1)

随笔档案

aspnet

搜索

最新评论

阅读排行榜

评论排行榜