日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
實例VB.NET常用代碼歸納總結(jié)

學習中就在善于總結(jié),在VB.NET中有很多常用的代碼,在這里給大家總結(jié)了一點關(guān)于VB.NET常用代碼的實例,如果對大家有用的話,希望大家記下來,方便以后使用。

創(chuàng)新互聯(lián)專注于豐潤網(wǎng)站建設(shè)服務(wù)及定制,我們擁有豐富的企業(yè)做網(wǎng)站經(jīng)驗。 熱誠為您提供豐潤營銷型網(wǎng)站建設(shè),豐潤網(wǎng)站制作、豐潤網(wǎng)頁設(shè)計、豐潤網(wǎng)站官網(wǎng)定制、微信小程序定制開發(fā)服務(wù),打造豐潤網(wǎng)絡(luò)公司原創(chuàng)品牌,更為您提供豐潤網(wǎng)站排名全網(wǎng)營銷落地服務(wù)。

1. 打開新的窗口并傳送參數(shù)

傳送參數(shù):

 
 
 
  1. response.write("<script>window.open(’*.aspx?id="+this.DropDownList1.SelectIndex+"&id1="+...+"’)</script>") 

接收參數(shù):

 
 
 
  1. string a = Request.QueryString("id");  
  2. string b = Request.QueryString("id1"); 

2.為按鈕添加對話框

 
 
 
  1. Button1.Attributes.Add("onclick","return confirm(’確認?’)");  
  2. button.attributes.add("onclick","if(confirm(’are you sure...?’)){return true;}else{return false;}")  

3.刪除表格選定記錄

 
 
 
  1. int intEmpID = (int)MyDataGrid.DataKeys[e.Item.ItemIndex];  
  2. string deleteCmd = "DELETE from Employee where emp_id = " + intEmpID.ToString() 

4.刪除表格記錄警告

 
 
 
  1. private void DataGrid_ItemCreated(Object sender,DataGridItemEventArgs e)  
  2. {  
  3. switch(e.Item.ItemType)  
  4. {  
  5. case ListItemType.Item :  
  6. case ListItemType.AlternatingItem :  
  7. case ListItemType.EditItem:  
  8. TableCell myTableCell;  
  9. myTableCell = e.Item.Cells[14];  
  10. LinkButton myDeleteButton ;  
  11. myDeleteButton = (LinkButton)myTableCell.Controls[0];  
  12. myDeleteButton.Attributes.Add("onclick","return confirm(’您是否確定要刪除這條信息’);");  
  13. break;  
  14. default:  
  15. break;  
  16. }  

5.點擊表格行鏈接另一頁

 
 
 
  1. private void grdCustomer_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)  
  2. {  
  3. //點擊表格打開  
  4. if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)  
  5. e.Item.Attributes.Add("onclick","window.open(’Default.aspx?id=" + e.Item.Cells[0].Text + "’);");  
  6. }  
  7. //雙擊表格連接到另一頁  
  8. //在itemDataBind事件中  
  9. if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)  
  10. {  
  11. string OrderItemID =e.item.cells[1].Text;  
  12. ...  
  13. e.item.Attributes.Add("ondblclick", "location.href=’../ShippedGrid.aspx?id=" + OrderItemID + "’");  
  14. }  
  15. //雙擊表格打開新一頁  
  16. if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)  
  17. {  
  18. string OrderItemID =e.item.cells[1].Text;  
  19. ...  
  20. e.item.Attributes.Add("ondblclick", "open(’../ShippedGrid.aspx?id=" + OrderItemID + "’)");  

6.表格超連接列傳遞參數(shù)

 
 
 
  1. <asp:HyperLinkColumn Target="_blank" headertext="ID號" DataTextField="id" NavigateUrl="aaa.aspx?id=’  
  2. <%# DataBinder.Eval(Container.DataItem, "數(shù)據(jù)字段1")%>’ & name=’<%# DataBinder.Eval(Container.DataItem, "數(shù)據(jù)字段2")%>’ /> 

7.表格點擊改變顏色

 
 
 
  1. if (e.Item.ItemType == ListItemType.Item ||e.Item.ItemType == ListItemType.AlternatingItem)  
  2. {  
  3. e.Item.Attributes.Add("onclick","this.style.backgroundColor=’#99cc00’;  
  4. this.style.color=’buttontext’;this.style.cursor=’default’;");  
  5. }   
  6. //寫在DataGrid的_ItemDataBound里  
  7. if (e.Item.ItemType == ListItemType.Item ||e.Item.ItemType == ListItemType.AlternatingItem)  
  8. {  
  9. e.Item.Attributes.Add("onmouseover","this.style.backgroundColor=’#99cc00’;  
  10. this.style.color=’buttontext’;this.style.cursor=’default’;");  
  11. e.Item.Attributes.Add("onmouseout","this.style.backgroundColor=’’;this.style.color=’’;");  

8.VB.NET常用代碼關(guān)于日期格式

日期格式設(shè)定

 
 
 
  1. DataFormatString="{0:yyyy-MM-dd}" 

我覺得應(yīng)該在itembound事件中

 
 
 
  1. e.items.cell["你的列"].text=DateTime.Parse(e.items.cell["你的列"].text.ToString("yyyy-MM-dd"))  

9.獲取錯誤信息并到指定頁面

不要使用Response.Redirect,而應(yīng)該使用Server.Transfer

 
 
 
  1. e.g  
  2. // in global.asax  
  3. protected void Application_Error(Object sender, EventArgs e) {  
  4. if (Server.GetLastError() is HttpUnhandledException)  
  5. Server.Transfer("MyErrorPage.aspx");  
  6. //其余的非HttpUnhandledException異常交給ASP.NET自己處理就okay了 :)  

Redirect會導(dǎo)致post-back的產(chǎn)生從而丟失了錯誤信息,所以頁面導(dǎo)向應(yīng)該直接在服務(wù)器端執(zhí)行,這樣就可以在錯誤處理頁面得到出錯信息并進行相應(yīng)的處理

10.VB.NET常用代碼清空Cookie

 
 
 
  1. Cookie.Expires=[DateTime];  
  2. Response.Cookies("UserName").Expires = 0 

【編輯推薦】

  1. 剖析VB.NET平臺調(diào)用是如何執(zhí)行操作
  2. 分享個人總結(jié)VB.NET多線程
  3. 詳細說明VB.NET變量中四點
  4. 三類十二種VB.NET數(shù)據(jù)類型全面介紹
  5. VB.NET初步知識,初學者必看

網(wǎng)頁標題:實例VB.NET常用代碼歸納總結(jié)
標題鏈接:http://www.dlmjj.cn/article/cceeosh.html