1. the dialog box is displayed. Click to go to the specified page.
CODE: Response. Write ("<script> window. alert ('This member has not submitted an application. Please submit it again! ') </Script> "); Response. Write ("<script> window. location = 'HTTP: // www.51aspx.com/bizpulic/upmeb.aspx' </script> "); |
2. Dialog Box
CODE: Response. Write ("<script language = 'javascript '> alert ('product added successfully! ') </Script> "); |
3. delete an object
CODE: string filename ="20059595157517.jpg"; pub.util.DeleteFile(HttpContext.Current.Server.MapPath ("../file/")+filename); |
4. Bind the drop-down list box datalist
CODE: System. data. dataView dv = conn. exec_ex ("select-1 as code, 'Please select business mode' as content from dealin union select code, content from dealin"); this. dealincode. dataSource = dv; this. dealincode. dataTextField = "content"; this. dealincode. dataValueField = "code"; this. dealincode. dataBind (); this. dealincode. items. findByValue (dv [0] ["dealincode"]. toString ()). selected = true;
5. display time in seconds
CODE:<%# System.DateTime.Parse(DataBinder.Eval(Container.DataItem,"beg time").ToString()).ToShortDateString()%> |
6. Link to the title
CODE:<%# "<a class=\"12c\" target=\"_blank\" href=\"http://www.51aspx/ CV/_"+DataBinder.Eval(Container.DataItem,"procode")+".html\ ">"+ DataBinder.Eval(Container.DataItem,"proname")+"</a>"%> |
7. Modify the redirection
CODE: <% # "<A href = \" editpushpro. aspx? Id = "+ DataBinder. Eval (Container. DataItem, "Code") + "\"> "+" modify "+" </A> "%> |
8. The OK button is displayed.
CODE: <% # "<A id = \" btnDelete \ "onclick = \" return confirm ('Are you sure you want to delete this Record? '); \ "Href = \" pushproduct. aspx? Dl = "+ DataBinder. Eval (Container. Data Item, "code") + "\"> "+" delete "+" </A> "%> |
9. The output data format "{0: F2}" is in the format of F2, indicating that there are two digits after the decimal point
CODE:<%# DataBinder.Eval(Container, "DataItem.PriceMoney","{0:F2}") %> |
10. Extract dynamic webpage content
CODE:Uri uri = new Uri("http://www.51aspx.com/"); WebRequest req = WebRequest.Create(uri); WebResponse resp = req.GetResponse(); Stream str = resp.GetResponseStream(); StreamReader sr = new StreamReader(str,System.Text.Encoding.Default); string t = sr.ReadToEnd(); this.Response.Write(t.ToString()); |
11. Get the characters After "."
CODE:i.ToString().Trim().Substring(i.ToString().Trim().LastIndexOf(".") +1).ToLower().Trim() |
12. open a new window and send parameters:
Transfer Parameters:
CODE:response.write("<script>window.open(’*.aspx?id="+this.DropDownList1.SelectI ndex+"&id1="+...+"’)</script>") |
Receiving parameters:
CODE:string a = Request.QueryString("id");string b = Request.QueryString("id1"); |
12. Add dialog box for button
CODE: Button1.Attributes. Add ("onclick", "return confirm ('OK? ') "); Button. attributes. add (" onclick "," if (confirm ('Are you sure ...? ') {Return true;} el Se {return false ;}") |
13. Delete selected table records
CODE:int intEmpID = (int)MyDataGrid.DataKeys[e.Item.ItemIndex];string deleteCmd = "Delete from Employee where emp_id = " + intEmpID.ToString() |
14. Delete table record warning
CODE: 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 info');"); break; default: break ;}}
15. Click the table row link to another page.
CODE: private void grdCustomer_ItemDataBound (object sender, System. Web. UI. WebContr Ols. DataGridItemEventArgs e) {// click the table to open if (e. Item. ItemType = ListItemType. Item | e. Item. Ite MType = ListItemType. AlternatingItem) e. Item. Attributes. Add ("onclick", "window. open ('default. aspx? Id = "+ e. Ite M. Cells [0]. Text + "');");} |
Double-click a table to connect to another page
In the itemDataBind event
CODE:if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.Alter natingItem){string orderItemID =e.item.cells[1].Text;e.item.Attributes.Add("ondblclick", "location.href=’../ ShippedGrid.aspx?id=" + orderItemID + "’");} |
Double-click a table to open a new page.
CODE:if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListIt emType.AlternatingItem){string orderItemID =e.item.cells[1].Text;e.item.Attributes.Add("ondblclick", "open(’../ShippedGrid.aspx?id=" + orderI temID + "’)");} |
- ASP. NET practical code 2)
- ASP. NET practical code 3)
- ASP. net mvc Case study 1)