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

首頁 > 編程 > .NET > 正文

ASP.NET程序中常用代碼匯總(一)

2024-07-10 13:06:48
字體:
來源:轉載
供稿:網(wǎng)友

1. 打開新的窗口并傳送參數(shù): //傳送參數(shù):
response.write("<script>window.open(’*.aspx?id="+this.dropdownlist1.selectindex+"&id1="++"’)</script>")
  //接收參數(shù):
string a = request.querystring("id");
string b = request.querystring("id1");2.為按鈕添加對話框
button1.attributes.add("onclick","return confirm(’確認?’)");
button.attributes.add("onclick","if(confirm(’are you sure?’)){return true;}else{return false;}")3.刪除表格選定記錄
int intempid = (int)mydatagrid.datakeys[e.item.itemindex];
string deletecmd = "delete from employee where emp_id = " + intempid.tostring()4.刪除表格記錄警告
private void datagrid_itemcreated(object sender,datagriditemeventargs e)
{
 switch(e.item.itemtype)
 {
  case listitemtype.item :
  case listitemtype.alternatingitem :
  case listitemtype.edititem:
   tablecell mytablecell;
   mytablecell = e.item.cells[14];
   linkbutton mydeletebutton ;
   mydeletebutton = (linkbutton)mytablecell.controls[0];
   mydeletebutton.attributes.add("onclick","return confirm(’您是否確定要刪除這條信息’);");
   break;
  default:
   break;
 }
}
5.點擊表格行鏈接另一頁
private void grdcustomer_itemdatabound(object sender, system.web.ui.webcontrols.datagriditemeventargs e)
{
 //點擊表格打開
 if (e.item.itemtype == listitemtype.item || e.item.itemtype == listitemtype.alternatingitem)
  e.item.attributes.add("onclick","window.open(’default.aspx?id=" + e.item.cells[0].text + "’);");
}
  //雙擊表格連接到另一頁
  //在itemdatabind事件中
if(e.item.itemtype == listitemtype.item || e.item.itemtype == listitemtype.alternatingitem)
{
 string orderitemid =e.item.cells[1].text;
 
 e.item.attributes.add("ondblclick", "location.href=’../shippedgrid.aspx?id=" + orderitemid + "’");
}
   //雙擊表格打開新一頁
if(e.item.itemtype == listitemtype.item || e.item.itemtype == listitemtype.alternatingitem)
{
 string orderitemid =e.item.cells[1].text;
 
 e.item.attributes.add("ondblclick", "open(’../shippedgrid.aspx?id=" + orderitemid + "’)");
}
  ★特別注意:【?id=】 處不能為 【?id =】6.表格超連接列傳遞參數(shù)
<asp:hyperlinkcolumn target="_blank" headertext="id號" datatextfield="id" navigateurl="aaa.aspx?id=’
 <%# databinder.eval(container.dataitem, "數(shù)據(jù)字段1")%>’ & name=’<%# databinder.eval(container.dataitem, "數(shù)據(jù)字段2")%>’ />7.表格點擊改變顏色
if (e.item.itemtype == listitemtype.item ||e.item.itemtype == listitemtype.alternatingitem)
{
 e.item.attributes.add("onclick","this.style.backgroundcolor=’#99cc00’;
    this.style.color=’buttontext’;this.style.cursor=’default’;");
}
  寫在datagrid的_itemdatabound里
if (e.item.itemtype == listitemtype.item ||e.item.itemtype == listitemtype.alternatingitem)
{
e.item.attributes.add("onmouseover","this.style.backgroundcolor=’#99cc00’;
   this.style.color=’buttontext’;this.style.cursor=’default’;");
e.item.attributes.add("onmouseout","this.style.backgroundcolor=’’;this.style.color=’’;");
}

8.關于日期格式

日期格式設定
dataformatstring="{0:yyyy-mm-dd}"
  //我覺得應該在itembound事件中
e.items.cell["你的列"].text=datetime.parse(e.items.cell["你的列"].text.tostring("yyyy-mm-dd"))9.獲取錯誤信息并到指定頁面
//不要使用response.redirect,而應該使用server.transfer
  e.g
// in global.asax
protected void application_error(object sender, eventargs e) {
if (server.getlasterror() is httpunhandledexception)
server.transfer("myerrorpage.aspx");

//其余的非httpunhandledexception異常交給asp.net自己處理就okay了 :)
}
  //redirect會導致post-back的產(chǎn)生從而丟失了錯誤信息,所以頁面導向應該直接在服務器端執(zhí)行,這樣就可以在錯誤處理頁面得到出錯信息并進行相應的處理 10.清空cookie cookie.expires=[datetime];
response.cookies("username").expires = 0
web窗體狀態(tài)欄內(nèi)類似跑馬等效果的實現(xiàn)
第一步:定義一個javascript代碼段

<script language="javascript">
var strmsg = "          歡迎光臨本站點by lovefxn          ";
function doload(index)
{
window.status = strmsg.substr(index,index+10);
index = (index>=strmsg.length-10?0:index+1);
window.settimeout('doload('+index+')',300,"javascript");
}
</script>

該代碼的功能是:每隔300毫秒則執(zhí)行一次窗體狀態(tài)欄內(nèi)容的更新,并對顯示內(nèi)容長度作判斷。

注意其中strmsg內(nèi)的空格用來實現(xiàn)一段空白效果。

第二步:

在 <body >內(nèi)添加函數(shù)的實現(xiàn)。

看看效果,是不是比較好玩?

 

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 宁陕县| 两当县| 咸阳市| 昭通市| 敦化市| 莫力| 聊城市| 礼泉县| 忻城县| 社会| 布尔津县| 武鸣县| 遵化市| 德令哈市| 道真| 岚皋县| 泰来县| 罗江县| 芷江| 萨迦县| 视频| 富川| 柯坪县| 航空| 古浪县| 庄浪县| 镇雄县| 眉山市| 吉安市| 泌阳县| 乳山市| 莒南县| 石河子市| 察雅县| 南昌市| 江津市| 凌海市| 德昌县| 苍溪县| 固镇县| 桦甸市|