Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the common codes in VB.NET?

2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

Editor to share with you what VB.NET commonly used code, I hope you will learn something after reading this article, let's discuss it together!

1. Open a new window and pass the parameters:

Transfer parameters:

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

Receive parameters:

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

two。 Add a dialog box for the button

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

3. Delete table selected record

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

4. Delete form record warning

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 ('are you sure you want to delete this message';"); break; default: break;}}

5. Click the table row link to another page

Private void grdCustomer_ItemDataBound (object sender, System.Web.UI.WebControls.DataGridItemEventArgs e) {/ / Click on the table to open 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 + ");") } / / double-click the table to connect to another page / / in the itemDataBind event 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 + "'");} / double-click the table to open a new page 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 + "')");}

6. Table hyperjoin column pass parameters

< asp:HyperLinkColumn Target= "_ blank" headertext= "ID number" DataTextField= "id" NavigateUrl= "aaa.aspx?id=' <% # DataBinder.Eval (Container.DataItem," data Field 1 ")% >'& name=' <% # DataBinder.Eval (Container.DataItem," data Field 2 ")% > / >

7. Click to change the color of the form

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';");} / / if (e.Item.ItemType = = ListItemType.Item | | e.Item.ItemType = = ListItemType.AlternatingItem) {e.Item.Attributes.Add ("onmouseover", "this.style.backgroundColor='#99cc00'") in the _ ItemDataBound of DataGrid This.style.color='buttontext';this.style.cursor='default'; "); e.Item.Attributes.Add (" onmouseout "," this.style.backgroundColor='';this.style.color=''; ");}

8.VB.NET Common Code about date format

Date format setting

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

I think it should be in the itembound incident

E.items.cell ["your column"] .text = DateTime.Parse (e.items.cell ["your column"] .text.ToString ("yyyy-MM-dd"))

9. Get the error message and go to the specified page

Instead of using Response.Redirect, you should use Server.Transfer

E.g / / in global.asax protected void Application_Error (Object sender, EventArgs e) {if (Server.GetLastError () is HttpUnhandledException) Server.Transfer ("MyErrorPage.aspx"); / / the rest of the non-HttpUnhandledException exceptions are left to ASP.NET to handle and okay:)}

Redirect will lead to the generation of post-back and lose the error message, so the page orientation should be executed directly on the server side, so that you can get the error message on the error handling page and deal with it accordingly.

10.VB.NET commonly used code to clear Cookie

Cookie.Expires= [DateTime]; Response.Cookies ("UserName"). Expires= 0 after reading this article, I believe you have a certain understanding of "what are the common codes in VB.NET". If you want to know more about it, welcome to follow the industry information channel, thank you for reading!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report