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)。
看看效果,是不是比較好玩?
新聞熱點
疑難解答
圖片精選