国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

即刻完成你的ASP.NET程序

2024-07-10 12:55:53
字體:
來源:轉載
供稿:網友
asp.net的出現,使網絡程序員們設計程序的時候完全找到了“設計程序”的感覺,當然,更多的,他們感覺到了asp.net的得心應手。但是,沒有想偷懶就沒有進步,如果你僅僅依靠asp.net自己的強大功能而不想其他手段,那你很快就會發現別人設計程序比你會快很多而且輕輕松松。現在,我們來學習幾招偷懶的手段,讓別人跟在你后面敬佩吧。
使用過asp的朋友一定都記得,asp的很多功能需要一些第三方的組件實現,比如文件上傳功能的實現就往往使用aspcnup組件實現。使用這些組件,不但可以擴展asp程序的功能,而且,大大提高程序開發速度。我們這里介紹的偷懶手段,也就是介紹幾款與我們平時設計密切相關的組件。
一、超級數據表格:superdatagrid
asp.net自帶的datgrid功能強大,定制也很方便,但是,因為它不是專門為數據庫應用設計的。所以,在連接數據庫的時候,我們不得不首先連接數據庫,然后綁定數據。而superdatagrid是專門為數據庫設計的,所以,那些繁瑣的連接數據庫我們也就沒有必要去寫了。需要
superdatagrid將datagrid的一些屬性簡單化,使用這個控件,我們可以方便的實現數據庫數據的顯示、排序、修改數據,這些功能的實現,只要簡單幾行代碼就可以。我們現在來看它的使用。
一)顯示數據表
以下代碼演示怎樣使用superdatagrid來簡單的顯示數據表中的所有數據:
<%@ register tagprefix="super" namespace="superexpert.data"
assembly="superexpert.superdatagrid" %>

<super:superdatagrid
connectionstring="server=localhost;uid=demo;pwd=secret;database=pubs"
tablename="titles"
runat="server" />
具體效果請看:
http://www.superexpertcontrols.com/superdatagrid/samples/sample1.aspx
現在,我們來簡單分析以上代碼。第一行使調用superdatagrid控件,我們在以后的舉例中都將使用到。第二行,和標準的datagrid使用差不多,我們看看superdatagrid的一些屬性:
connectionstring:因為是連接數據庫,當然少不了數據庫連接語句。這個參數就是連接數據的語句;
tablename:要顯示具體的表,我們就在這里定義。
看到這里,我們已經感覺到了“簡單”,但是,在實際的應用中,像這種直接顯示一個表的情況是很少的。所以,我們需要其他更多的功能。最直接的,我們需要select語句的返回結果。
<%@ register tagprefix="super" namespace="superexpert.data"
assembly="superexpert.superdatagrid" %>

<super:superdatagrid
connectionstring="server=localhost;uid=sa;pwd=secret;database=northwind"
commandtext="select productname, categoryname  
from products, categories where products.categoryid=categories.categoryid"
runat="server" />
具體效果請看:
http://www.superexpertcontrols.com/superdatagrid/samples/sample2.aspx
以上代碼返回select語句的結果。在這里,我們見到一個新的屬性:
commandtext:和command一樣,就是select語句;
二)數據排序
在datagrid中,數據排序雖然簡單,但是代碼還是不少。我們現在來看superdatagrid中怎樣給數據排序:
<%@ register tagprefix="super" namespace="superexpert.data"
assembly="superexpert.superdatagrid" %>

<form runat="server">
<super:superdatagrid
connectionstring="server=localhost;uid=sa;pwd=secret;database=pubs"
tablename="titles"
enablesorting="true"  
runat="server" />  
</form>
具體效果請看:
http://www.superexpertcontrols.com/superdatagrid/samples/sample3.aspx
仔細看以上代碼,其實就是設置了一個enablesortinga屬性為真。也就是打開排序功能。需要仔細注意的一點,要將superdatagrid包括在form中。
三)數據分頁
在asp中,很多朋友會為分頁煩惱,現在,我們看看superdatagrid中怎樣分頁:
<%@ register tagprefix="super" namespace="superexpert.data"
assembly="superexpert.superdatagrid" %>

<form runat="server">
<super:superdatagrid
connectionstring="server=localhost;uid=sa;pwd=secret;database=pubs"
tablename="titles"
enablepaging="true"
pagesize="3"
pagerstyle-mode="numericpages"
runat="server" />  
</form>
具體效果請看:
http://www.superexpertcontrols.com/superdatagrid/samples/sample4.aspx
我們來看看superdatagrid的幾個新屬性:
enablepaging:首先,我們當然要打開數據分頁;
pagesize:和datagrid一樣,每頁數據顯示的條數;
pagerstyle-mode:和datagrid一樣,頁碼顯示方式;
四)數據編輯
我們知道,在datagrid中,我們可以在直接編輯數據,但是,一般我們很少使用這樣功能,因為這樣編輯數據不是很方便也不是很實用,代碼編寫也比較多。現在,superdatagrid也提供這個功能,當然,我們不需要寫那么多代碼,只需要簡單的設置就可以,其他,superdatagrid全部幫我們弄好了。
<%@ register tagprefix="super" namespace="superexpert.data"
assembly="superexpert.superdatagrid" %>

<form runat="server">
<super:superdatagrid
connectionstring="server=localhost;uid=sa;pwd=secret;database=northwind"
tablename="products"
enableediting="true"
enablepaging="true"
runat="server" />  
</form>
具體效果請看:
http://www.superexpertcontrols.com/superdatagrid/samples/sample5.aspx
看以上代碼,如果需要編輯數據,只要加enableediting屬性就可以了。是不是特別簡單?當然,我們仍然要將superdatagrid放在form中。
五)緩存
asp.net的緩存功能我們已經知道很強大,但是,具體到superdatagrid,你會發現它更加方便。使用superdatagrid的時候,會自動緩存已經顯示過的數據來提高程序效率。設置緩存功能可以使用cachescope屬性,我們可以設置緩存類型為application,,session和 none。
superdatagrid默認緩存類型為application,也就是所有用戶共用緩存;如果采用session,緩存只針對特殊的用戶;如果設置為none,那就是不要緩存功能。
默認的,緩存會保持30分鐘,當然,我們可以使用cacheduration屬性設置緩存時間,單位為分鐘。

二、超級表單:superexpert dataform
剛才我們看到superdatagrid已經具有數據修改功能,但是,由于數據瀏覽和修改同時進行,實際上我們很少使用那種方式,更多的,我們還說采用單個記錄修改。
以往我們在使用表單修改或者增加數據庫數據的時候,需要作的工作很多,比如設置數據格式等,如果數據比較多,那更加繁瑣。現在,使用superexpert dataform,我們可以簡單的實現這些功能。
superexpert dataform可以自動保存或者修改數據庫數據,還可以使用它自動從數據庫生成表單(實際是瀏覽數據),我們甚至可以自定義樣式來自動修改、更新數據庫表。
一)從數據庫自動生成表單
假設我們使用以下sql語句生成一個叫customersurveys的數據表:
create table customersurvey
(
customer_id int not null identity primary key,
customer varchar( 50 ) not null,
age int not null,
birthdate datetime not null,
comments text
)
這個數據表有customer_id、customer、 age、birthdate和comments五個字段。我們可以使用superexpert dataform自動生成一個表單,使用這個表單,我們可以直接向該數據表增加數據。
<%@ register tagprefix="super" namespace="superexpert.data"
assembly="superexpert.dataform" %>

<html>
<head><title>simpledataform.aspx</title></head>
<body>

<super:sqldataform
tablename="customersurvey"
connectionstring="server=localhost;uid=sa;pwd=secret;database=pubs"
mode="addrecord"
runat="server" />

</body>
</html>
具體效果如下:
http://www.superexpertcontrols.com/dataform/samples/sample1.aspx
為了更好的理解superexpert dataform,我們必須了解那些東西是可以自動生成的:
1、表單中的textbox寬度是根據數據表數據寬度自動生成的;
2、填入表單中數據的驗證是自動生成的。如果數據表要求數據不為null,那么提交表單的時候就要求輸入;如果數據為int,要求填入integer;如果數據為datetime,要求填入datetime數據。
3、點擊提交按鈕以后,數據自動保存到數據表。
所有我們要做的只是提供數據表名稱和數據庫連接字符串。
二)設置dataform模式
dataform有以下幾種模式:
1、addrecord:增加數據模式;
2、updaterecord:修改單條數據模式;
3、updatetable:成批修改數據模式;
4、custom:提交數據時可以自己設置邏輯驗證;
為了修改一條已經存在的數據,我們必須設置dataform模式為updaterecord。然后,我們必須確定修改那一條數據,我們通過datakeyfield和datakeyvalue唯一確定一條數據,datakeyfield是數據表主鍵;datakeyvalue是一條數據的主鍵的值。
以下代碼修改數據表中第三條記錄:
<%@ register tagprefix="super" namespace="superexpert.data"
assembly="superexpert.dataform" %>

<html>
<head><title>dataformupdaterecord.aspx</title></head>
<body>

<super:sqldataform
tablename="customersurvey"
connectionstring="server=localhost;uid=sa;pwd=secret;database=pubs"
datakeyfield="customer_id"
datakeyvalue="3"
mode="updaterecord"
runat="server" />

</body>
</html>
具體效果如下:
http://www.superexpertcontrols.com/dataform/samples/sample2.aspx
以上代碼設置mode為updaterecord,設置datakeyfield為customer_id,設置datakeyvalue為3。
如果我們需要修改數據表中的所有數據,可以將dataform模式設置為updatetable。在設置為修改整個表以后,會在數據表單上方生成一個導航條,通過這個導航條,我們可以瀏覽數據表中的所有數據。
<%@ register tagprefix="super" namespace="superexpert.data"
assembly="superexpert.dataform" %>

<html>
<head><title>dataformupdatetable.aspx</title></head>
<body>

<super:sqldataform
tablename="customersurvey"
connectionstring="server=localhost;uid=sa;pwd=secret;database=pubs"
datakeyfield="customer_id"
mode="updatetable"
runat="server" />

</body>
</html>
具體效果如下:
http://www.superexpertcontrols.com/dataform/samples/sample3.aspx
如果我們將模式設置為custom,我們就可以設置提交表單以后的動作。比如,以下代碼實現提交表單以后自動轉到thankyou.aspx頁面。
<%@ register tagprefix="super" namespace="superexpert.data"
assembly="superexpert.dataform" %>

<script runat="server">

sub form_submit( s as object, e as eventargs )
myform.save()
response.redirect( "thankyou.aspx" )
end sub

</script>

<html>
<head><title>dataformcustom.aspx</title></head>
<body>

<super:sqldataform
id="myform"
tablename="customersurvey"
connectionstring="server=localhost;uid=sa;pwd=secret;database=pubs"
mode="custom"
onsubmit="form_submit"
runat="server" />

</body>
</html>
具體效果如下:
http://www.superexpertcontrols.com/dataform/samples/sample4.aspx
三)設置dataform樣式
dataform有四種樣式我們可以修改:
1、headerstyle:定義數據表單的header樣式;
2、labelstyle:定義數據表單的label樣式;
3、fieldstyle:定義數據表單的field樣式;
4、footerstyle:定義數據表單的footer樣式;
dataform還支持以下屬性設置:
gridlines:定義數據表單的線格式,包括:none、both、horizontal和vertical。
height:數據表單控件高度;
width:數據表單控件寬度;
boderstyle:數據表單邊框格式;
borderwidth:數據表單邊框寬度;
bordercolor:數據表單邊框顏色;
cellpadding:數據表單控件大小;
cellspacing:數據表單控件間間距;
我們現在看一個舉例:
<%@ register tagprefix="super" namespace="superexpert.data"
assembly="superexpert.dataform" %>

<html>
<head><title>dataformstyle.aspx</title></head>
<body>

<super:sqldataform
headerstyle-backcolor="salmon"
fieldstyle-backcolor="yellow"
labelstyle-font-name="script"
labelstyle-font-size="28pt"
footerstyle-backcolor="blue"
cellpadding="10"
cellspacing="0"
gridlines="both"
borderstyle="dashed"
bordercolor="red"
borerwidth="10px"
labelstyle-backcolor="lightgreen"
tablename="customersurvey"
connectionstring="server=localhost;uid=sa;pwd=secret;database=pubs"
runat="server" />

</body>
</html>
具體效果如下:
http://www.superexpertcontrols.com/dataform/samples/sample5.aspx
四)自定義布局的dataform
我們也可以自己增加控件設計數據表單布局,可以增加的控件如下:
● datatextbox  
● datadropdownlist  
● dataradiobutton  
● datacheckbox  
● datalistbox  
● dataradiobuttonlist  
● datalabel
沒一個控件都擴展了標準控件的功能。這些控件都有兩個屬性:datafield和datatype。datafield讓控件和數據庫的具體字段聯系起來,datatype定義輸入數據的類型。以下是一個增加數據的舉例:
<%@ register tagprefix="super" namespace="superexpert.data"
assembly="superexpert.dataform" %>

<script runat="server">

sub form_submit( s as object, e as eventargs )
myform.save()
response.redirect( "thankyou.aspx" )
end sub

</script>

<html>
<head><title>dataformcustomlayout.aspx</title></head>
<body>

<super:sqldataform
id="myform"
tablename="customersurvey"
connectionstring="server=localhost;uid=sa;pwd=secret;database=pubs"
runat="server">

customer name:
<br>
<super:datatextbox
datafield="customer"
runat="server" />

<p>
age:
<br>
<super:datatextbox
datafield="age"
runat="server" />

<p>
birthdate:
<br>
<super:datatextbox
datafield="birthdate"
runat="server" />

<p>
<asp:button
text="add new customer!"
onclick="form_submit"
runat="server" />
<p>  
</super:sqldataform>

</body>
</html>
具體效果請看:
http://www.superexpertcontrols.com/dataform/samples/sample6.aspx

三、超級圖像文字控件:superexpert imagetext
我們知道,asp.net可以將文字生成圖象,只是,對我大部分用戶而言,這些功能藏的有點深。superexpert imagetext讓我們可以很簡單的實現將文字生成圖象。我們可以使用安裝在服務器上的任何一款字體來生成圖象,也可以使用我們下面將要提到的所有圖象特效來生成圖象。
我們可以利用superexpert imagetext來快速的生成圖象,它的好處是我們可以完全控制文字的樣式。
一)自動生成圖象
要使用superexpert imagetext,我們只要簡單的提供一個唯一id和需要轉化的文字。下面的舉例將生成“hello world”:
<%@ register tagprefix="super" namespace="superexpert"
assembly="superexpert.imagetext" %>

<super:imagetext
id="ctrlhello"
text="hello world!"
runat="server"/>
具體效果請看:
http://www.superexpertcontrols.com/imagetextbeta2/samples/sample1.aspx
為了取得更好的效果,我們可以為文字設置字體和顏色,也可以設置圖象背景,下面的舉例就是這樣:
<%@ register tagprefix="super" namespace="superexpert"
assembly="superexpert.imagetext" %>


<super:imagetext
id="ctrlcomic"
text="hello world!"
font-name="comic sans ms"
font-size="34"
forecolor="darkblue"
runat="server"/>

<p>


<super:imagetext
id="ctrlimpact"
text="hello world!"
font-name="impact"
font-size="24"
forecolor="red"
backcolor="black"
runat="server"/>
具體效果請看:
http://www.superexpertcontrols.com/imagetextbeta2/samples/sample2.aspx
需要了解的是,無論采用什么字體,只要服務器上安裝了所使用的字體就行,只要已經轉化為圖象,所有瀏覽器都可以正確的顯示。
二)陰影特效
通過設置dropshadow屬性,我們可以將文字轉化為帶有陰影效果的圖象:
<%@ register tagprefix="super" namespace="superexpert"
assembly="superexpert.imagetext" %>

<super:imagetext
id="ctrldrop"
text="hello world!"
font-name="impact"
font-size="34"
dropshadow-display="true"
dropshadow-xoffset="3"
runat="server"/>
具體效果如下:
http://www.superexpertcontrols.com/imagetextbeta2/samples/sample3.aspx
針對陰影效果,我們還可以設置以下屬性來增強:
● dropshadow-xoffset:水平方向偏移
● dropshadow-yoffset :垂直方向偏移
● dropshadow-alpha :設置陰影透明度
● dropshadow-color :設置陰影顏色
三)旋轉文字效果
通過設置文字的rotateflip屬性,我們可以將文字進行旋轉:
<%@ register tagprefix="super" namespace="superexpert"
assembly="superexpert.imagetext" %>

<super:imagetext
id="ctrlhello"
text="hello world!"
font-size="24"
rotateflip="rotate90flipnone"
runat="server"/>

<p>

<super:imagetext
id="ctrlhello2"
text="hello world!"
font-size="24"
rotateflip="rotate180flipnone"
runat="server"/>
具體效果請看:
http://www.superexpertcontrols.com/imagetextbeta2/samples/sample4.aspx
四)控制圖象背景
我們可以設置背景為漸進顏色、圖片或者特殊圖案,以下是一個漸進顏色背景的舉例:
<%@ register tagprefix="super" namespace="superexpert"
assembly="superexpert.imagetext" %>

<super:imagetext
id="ctrlhello"
background-gradient="true"
cellpadding="4"
text="hello world!"
runat="server"/>
具體效果請看:
http://www.superexpertcontrols.com/imagetextbeta2/samples/sample5.aspx
我們還可以使用background-hatchstyle屬性來設置特殊背景圖案和圖案顏色,以下舉例就是一個波紋圖案背景的圖象:
<%@ register tagprefix="super" namespace="superexpert"
assembly="superexpert.imagetext" %>

<super:imagetext
id="ctrlhello"
cellpadding="10"
background-hatchstyle="weave"
background-startcolor="green"
text="hello world!"
runat="server"/>
具體效果請看:
http://www.superexpertcontrols.com/imagetextbeta2/samples/sample6.aspx
五)多行文字
通過設置圖象的寬度,可以實現多行文字的效果:
<%@ register tagprefix="super" namespace="superexpert"
assembly="superexpert.imagetext" %>

<super:imagetext
id="ctrlhello"
text="this is a long paragraph that demonstrates how you can wrap text with the imagetext control"
cellpadding="20"
width="200"
backcolor="orange"
runat="server"/>
具體效果請看:
http://www.superexpertcontrols.com/imagetextbeta2/samples/sample7.aspx
六)定稿圖象
如果不想每次頁面變動都重新生成圖象,可以設置final屬性為true。

四、總結
以上介紹的一些控件,我們在平時的設計中用的可能都比較多,非常使用。在我我們潛心研究asp.net的同時,我們可以學習利用這些工具來提高我們的工作效率和工作效果。注冊會員,創建你的web開發資料庫,
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 荆州市| 扶余县| 三原县| 永登县| 鄂伦春自治旗| 沂南县| 楚雄市| 盐山县| 阳西县| 古蔺县| 子洲县| 武定县| 麻栗坡县| 师宗县| 丰原市| 舞阳县| 北宁市| 陇西县| 庆云县| 贵定县| 平遥县| 阳西县| 平塘县| 普安县| 左权县| 澜沧| 库伦旗| 遵义县| 哈密市| 哈尔滨市| 楚雄市| 伊川县| 昌江| 肃宁县| 峡江县| 安岳县| 聂拉木县| 甘洛县| 巩义市| 明水县| 吴桥县|