20101211

1.  Web config文件:

数据库连接字符串:

<connectionStrings>

             <add name="SqlCon" connectionString="连接字符串 "/>

</connectionStrings>

在程序中读取连接字符串:

SqlConnection sc=new SqlConnection (System. Web.Configuration.WebConfigurationManager.ConnectionStrings["SqlCon"].ConnectionString);

2.  自定义控件freetextbox控件:

首先在web.config 加入以下代码,防止出错:

<pages validateRequest="false">

然后引用freetextbox控件相关文件,freetextbox.dll文件。并将freetextbox文件夹引入到相关文件夹里。使用控件,设置相关属性,例如:

<FTB:FreeTextBox id="FreeTextBox1" runat="Server" Language ="zh-CN" ImageGalleryPath

="../Image/"  ToolbarLayout="FontFacesMenu, FontSizesMenu,

FontForeColorsMenu,FontForeColorPicker, FontBackColorsMenu, FontBackColorPicker, Bold,

Italic, Underline| Strikethrough, Superscript, Subscript, InsertImageFromGallery,

CreateLink, Unlink, RemoveFormat, JustifyLeft, JustifyRight, JustifyCenter, JustifyFull,

BulletedList, NumberedList, Indent, Outdent | Cut, Copy, Paste, Delete, Undo, Redo, Print,

StyleMenu, SymbolsMenu, InsertHtmlMenu, InsertRule, InsertDate, InsertTime, WordClean,

InsertImage, InsertTable, EditTable, InsertTableRowBefore, InsertTableRowAfter,

DeleteTableRow, InsertTableColumnBefore, InsertTableColumnAfter, DeleteTableColumn,

InsertForm, InsertTextBox, InsertTextArea, InsertRadioButton, InsertCheckBox,

InsertDropDownList, InsertButton, InsertDiv, Preview, SelectAll, EditStyle" Height="400px" ToolbarStyleConfiguration="Office2003"  

JavaScriptLocation="InternalResource" ButtonWidth="15" Width="620px"

                    HtmlModeDefaultsToMonoSpaceFont="True" />

ImageGallerPath属性:设置插入的图片存放的位置。

ToolbarLayout属性:设置控件可执行的操作,字体大小,字体,颜色,插入图片等。

(更多功能期待补充)

3.  Datalist控件相关:

删除功能:datalist中放一个linkbutton控件,执行删除功能。

protected void DataList1_DeleteCommand(object source, DataListCommandEventArgs e)

    {

        int picturenewsid =int.Parse(DataList1.DataKeys[e.Item.ItemIndex].ToString());

        DataDetail ddt = new DataDetail();

        ddt.DeletpicNews(picturenewsid);

 

        DataSet ds = ddt.GetPicnewsInfo();

        DataList1.DataSource = ds;

        DataList1.DataKeyField = "picturenewsid";

        DataList1.DataBind();

    }

分页技术:Label3显示总页数,Label6显示当前页数,Linkbutton2上一页,Linkbutton3下一页。相关绑定代码

public void dlBind()

    {

        DataDetail ddt = new DataDetail();

        DataSet ds = ddt.GetPicnewsInfo();

 

        int curpage = Convert.ToInt32(Label6.Text);

        PagedDataSource ps = new PagedDataSource();

        ps.DataSource = ds.Tables[0].DefaultView;

        ps.AllowPaging = true;

        ps.PageSize = 8;

        ps.CurrentPageIndex = curpage - 1;

        LinkButton2.Enabled = true;

        LinkButton3.Enabled = true;

        

        if (curpage == 1)

        {

            LinkButton2.Enabled = false;

        }

        if (curpage == ps.PageCount)

        {

            LinkButton3.Enabled = false;

        }

        Label3.Text = Convert.ToString(ps.PageCount);

 

        DataList1.DataSource = ps;

        DataList1.DataKeyField = "picturenewsid";

        DataList1.DataBind();

    }

4.  Gridview控件相关:

删除:在gridview控件加入commandField里的删除列。删除的相关代码:

protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)

    {

        int mienid = (int)GridView1.DataKeys[e.RowIndex].Value;

        DataDetail ddt = new DataDetail();

        ddt.DeleteMienInfo(mienid);

 

        DataSet ds = new DataSet();

        ds = ddt.GetMienInfo();

 

        GridView1.DataSource = ds;

        GridView1.DataKeyNames = new string[] { "mienid" };

        GridView1.DataBind();

}

自动编号:简历一个空列

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)

    {

        if (e.Row.RowIndex != -1)

        {

            int num = e.Row.RowIndex + 1;

            e.Row.Cells[0].Text = num.ToString();

        }

    }

绑定数据:

GridView1.DataSource = ds;

        GridView1.DataKeyNames = new string[] { "mienid" };

        GridView1.DataBind();

5.  图片以二进制形式存入数据库:

放置一个FileUpLoad控件,相关上传按钮。

int FileLen = FileUpload1.PostedFile.ContentLength;

HttpPostedFile hp = FileUpload1.PostedFile;

Byte[] mienpic = dwp.SavePicture(FileLen, hp);

//处理图片的方法

public Byte[] SavePicture(int FileLen,HttpPostedFile hp)

    {

        Byte[] photo = new Byte[FileLen];

        Stream sr = hp.InputStream;

        sr.Read(photo, 0, FileLen);

 

        return photo;

    }

6.  读取二进制形式的图片并显示.asxh文件:

在要显示图片的地方放置一个image控件,创建名为xxx.ashx的文件

Image1.ImageUrl = "~/backstage/Handler/picMienHandler.ashx?mienid=id;

Ashx文件代码如下:

<%@ WebHandler Language="C#" Class="picMienHandler" %>

 

using System;

using System.IO;

using System.Data;

using System.Web;

 

public class picMienHandler : IHttpHandler

{

    public void ProcessRequest(HttpContext context)

    {

        int picturenewsid = int.Parse(context.Request.QueryString["mienid"]);

        DataDetail ddt = new DataDetail();

        DataSet ds = ddt.GetMienInfo(picturenewsid);

 

        Byte[] photo = (Byte[])ds.Tables[0].Rows[0][3];

        MemoryStream ms = new MemoryStream(photo, 0, photo.Length);

 

        if (ms != null)

        {

            int buffersize = (int)ms.Length;

            byte[] buffer = new byte[buffersize];

            int countsize = ms.Read(buffer, 0, buffersize);

            context.Response.OutputStream.Write(buffer, 0, countsize);

        }

    }

   

    public bool IsReusable

    {

        get

        {

            return false;

        }

    }

}

7.  文件上传:

FileUpLoad控件;提交按钮,按钮代码如下:

string filepath = FileUpload1.PostedFile.FileName;

                    string filename = filepath.Substring(filepath.LastIndexOf("//") + 1);

                    FileInfo fi = new FileInfo(Server.MapPath("DyFile/" + filename));

string serverpath = Server.MapPath("DyFile/") + filename;

                        FileUpload1.PostedFile.SaveAs(serverpath);

8.  文件下载:

string path = Server.MapPath("FpFile/") + filename;

 

       FileInfo fi = new FileInfo(path);

        if (fi.Exists)

        {

            Response.Clear();

            Response.ClearHeaders();

            Response.Buffer = false;

            Response.ContentType = "application/octet-stream";

            Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(fi.Name, System.Text.Encoding.UTF8).Replace("+", "%20"));

            Response.AppendHeader("Content-Length", fi.Length.ToString());

            Response.WriteFile(path);

            Response.Flush();

            Response.End();

        }

文件删除:

string path = Server.MapPath("FpFile/") + filename;

 

       FileInfo fi = new FileInfo(path);

fi.Delete();

在对文件操作时,引用system.IO空间。

9.  页面传值(js获得前页面传来的的数据参数)

这个脚本的效果是实现折叠菜单,模仿QQ好友的效果:

var fnum=document.getElementById("<%=TextBox1.ClientID%>").value;

var onum=parseInt(fnum,10);

var closeState=new Array();

var ch=200;

function $(id)

{

   if(document.getElementById(id))

   {

       return document.getElementById(id);

   }

   else

   {

       alert("没有找到!");

   }

}

function $tag(id,tagName)

{

   return $(id).getElementsByTagName(tagName);

}

var Ds=$tag("DoorP","div");

var Ts=$tag("DoorP","h2");

if(Ds.length != Ts.length)

{

   alert("初始化失败!");

}

function showMe(Cid,Oid)

{

    var h=parseInt(Ds[Cid].style.height);

    var h2=parseInt(Ds[Oid].style.height);

    var dH=ch;

    if(h>0)

    {

        h=h-Math.ceil(h/3);

        Ds[Cid].style.height=h+"px";

    };

    if(h2<dH)

    {

        h2=h2+Math.ceil((dH-h2)/3);

        Ds[Oid].style.height=h2+"px";

    };

    if(h<=0&&h2>=dH)

    {

        clearTimeout(closeState[Cid]);

        return false;

    };

    closeState[Cid] = setTimeout("showMe("+Cid+","+Oid+")");

}

for(var i=0;i<=Ds.length;i++)

{

    if(i==onum)

    {

        Ds[i].style.height=ch+"px";

        Ts[i].className="title01";

    }

    else

    {

        Ds[i].style.height="0px";

        Ts[i].className="title02";

    }

    Ts[i].value=i;

    Ts[i].onclick=function(){if(onum==this.value){return false;};

                 Ts[onum].className="title02";

                 Ts[this.value].className="title01";

                 for(var i=0;i<closeState.length;i++){clearTimeout(closeState[i]);}

                 showMe(onum,this.value);

                 onum=this.value;

                 }

}

</script>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值