Asp.net| Programming | program
1, binding in the DataList of the DropDownList
private void Dlistorder_editcommand (object source, System.Web.UI.WebControls.DataListCommandEventArgs e)
{
Bind order Status
for (int i=0;i< (DropDownList) Dlistorder.items[e.item.itemindex]. FindControl ("Ddlflag")). items.count;i++)
{
if ((DropDownList) Dlistorder.items[e.item.itemindex]. FindControl ("Ddlflag")). Items[i]. Value = = dv. table.rows[0]["Orstatus"]. ToString ())
{
((DropDownList) Dlistorder.items[e.item.itemindex]. FindControl ("Ddlflag")). Items[i]. Selected = true;
}
}
}
2, another way to bind
Bound shipping Method
DataView Shiptype = Orderso.getshiptypelist ();
DropDownList Ddlshiptype = (DropDownList) Dlistorder.items[e.item.itemindex]. FindControl ("Ddlshiptype");
Ddlshiptype.datasource = Shiptype;
Ddlshiptype.datatextfield = "Stname";
Ddlshiptype.datavaluefield = "Stid";
Ddlshiptype.databind ();
Ddlshiptype.selectedindex = DdlShipType.Items.IndexOf (DdlShipType.Items.FindByValue (DV). table.rows[0]["Orshiptype"]. ToString ()));
3. Locate the DataList line when editing a record in a DataGrid nested inside the DataList
protected void Mylist_itemcommand (object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
if (E.item.itemtype = = ListItemType.Item | | E.item.itemtype = = ListItemType.AlternatingItem)
{
htmlinputhidden odid = (HtmlInputHidden) e.item.cells[0]. FindControl ("Odid");
DataListItem item = (DataListItem) e.item.parent.parent.parent;
DropDownList flag = (DropDownList) item. FindControl ("Ddlflag");
if (flag. SelectedIndex = 0)
{
if (E.commandname = "Delete")
{
int iodid = Convert.ToInt32 (odid. Value);
Delete Order Detail method
Orderso.deleteorderdetail (Iodid);
}
}
Else
{
Gdcic. Framework.Utility.MessageBox (This, "Modifyerror", "confirmed orders can not be modified!!");
Return
}
Dlistorder.edititemindex =-1;
Binddata ();
}
}
4. DataBinding-Binding expression:
1 Normal binding expression
<%# DataBinder.Eval (Container.DataItem, "ContactName")%>
2) text + binding expression
<asp:label id=lbldate runat= "server" text= ' <%# "[" + DataBinder.Eval (Container, "dataitem.newscreatedate") + "]"% > ' forecolor= ' Red ' ></asp:Label>
3 binding expression with display format
<%# DataBinder.Eval (Container, "dataitem.usactivedate", "{0:YYYY-MM-DD}")%>
4) Binding expressions and Modal boxes
<a href= ' <%# showmodalwin (convert.tostring (DataBinder.Eval, "Container.DataItem"), Convert.ToString (DataBinder.Eval (Container.DataItem, "Detailid")), Convert.ToString (DataBinder.Eval ( Container.DataItem, "Pictureid"))%> ' >
Where: The Showmodalwin () method in the background code file is defined as follows:
Protected string Showmodalwin (String pictureimage,string detailid,string Pictureid)
{
Return "window.showModalDialog (\" customers/showpictureinfo.aspx?pid= "+pictureimage+" &did= "+DetailID+" & Id= "+pictureid+" "," \ "\", "dialogheight:320px;dialogwidth:480px;center:yes;help:no;status:no;scroll:no\");
}
Or extract the parameters and define them individually as a variable:
Const string windowparamstring= "Dialogwidth:540px;dialogheight:420px;help:0;status:0;resizeable:1;scroll:no";
Page.registerstartupscript ("Functionscript", "<script language= ' JavaScript ') >window.showmodaldialog (' Edituserservice.aspx? Urid= "+iurid+", "," "+windowparamstring+") </script>);
5. Add a new line to an existing dataset
int Iurid=int. Parse (Session[globals.user_id_session_name]. ToString ());
DataSet myds=userso.getmapuserservicetoservicelist (Iurid);
Add a message line
DataRow mydr = myds. Tables[0]. NewRow ();
mydr["svhref"] = "http://211.155.23.77";
mydr["svname"] = "Administrative mail";
mydr["usenddate"] = System.DateTime.Now.AddDays (1);
myDS. Tables[0]. Rows.Add (MYDR);
DataView mydv=myds. Tables[0]. DefaultView;
if (myds. Tables[0]. rows.count!=0)
{
Mydv. rowfilter= "Usenddate> '" +system.datetime.now+ "" ";/not expired
Dguserservice.visible=true;
Dguserservice.datasource =MYDV;
Try
{
Dguserservice.databind ();
}
Catch
{
Dguserservice.currentpageindex =dguserservice.pagecount-1;
Dguserservice.databind ();
}
}
Else
{
Dguserservice.visible=false;
}
6. Join the Client validation control
Validating null values
<asp:requiredfieldvalidator id= "Valusername" runat= "Server" controltovalidate= "txtUserName" display= "None" Errormessage= "Please enter user name!!" ></asp:requiredfieldvalidator>
Verify URL
<asp:regularexpressionvalidator id= "Rev" runat= "Server" errormessage= "company URL is illegal [to have http://]! "Display=" None "controltovalidate=" Txtcpwebsite "validationexpression=" http://([\w-]+\.) +[\w-]+ (/[\w-/?%&=]*)? " ></asp:regularexpressionvalidator>
Verifying mailboxes
<asp:requiredfieldvalidator id= "RFV" runat= "Server" controltovalidate= "Txtcpemail" "None" display= " Please enter e-mail!! " ></asp:RequiredFieldValidator>
Verify ZIP Code
<asp:regularexpressionvalidator id= "REV5" runat= "server" errormessage= ZIP code is not legal! "Display=" None "controltovalidate=" Txtcppostcode "validationexpression=" \d{6} "></asp: Regularexpressionvalidator>
Display error messages
<asp:validationsummary id= "vs" runat= "server" showsummary= "False" showmessagebox= "True" ></asp: Validationsummary>
7. Use of enumeration types
1) Definition:
public enum Usertypeenum:byte
{
<summary>
Individual users
</summary>
individual = 0,
<summary>
Unit user
</summary>
Corporation = 1
}
2 How to use in code:
Usertypeenum ut = usertypeenum.corporation;
Gdcic. Entities.uservo Uservo = Gdcic. Facade.UserSO.GetUserVO (Urid);
UT = (usertypeenum) enum.parse (UserTypeEnum.Corporation.GetType (), uservo.urusertype);
if (ut = = usertypeenum.corporation)
{
... ...
}
The method of directly obtaining the value of its representative
Response.Write ("Enum value is:" +convert.toint32 (usertypeenum.individual));
8. Verify that the username must begin with a letter and cannot contain Chinese
String sUserName = TxtUsername.Text.Trim ();
if (! Regex.IsMatch (sUserName, "^[a-za-z].*"))
{
Utility.messagebox (This, "Nameformaterror", "User name to start with a letter, and do not use the Chinese name!!");
Return
}
9. How to fix IIS mappings after removing and reinstalling IIS
To run the Aspnet_regiis.exe utility:
1,
Click Start, and then click Run.
In the Open box, type cmd, and then press Enter.
At the command prompt, type the following command, and then press Enter:
"%windir%\microsoft.net\framework\ version \aspnet_regiis.exe"-I.
2. In this path, the version represents the version number of the. NET Framework installed on the server. When you type this command, you must replace this placeholder with the actual version number.
Registered Aspnet_isapi.dll;
Click Start, and then click Run.
In the Open text box, type the following, and then press Enter:
regsvr32%windir%\microsoft.net\framework\ version \aspnet_isapi.dll
Regsvr32 will return the registration results.
10, download the file method:
Response.appendheader ("Content-disposition", "attachment; Filename= "+ request.params (" link "). ToString)
Response.ContentType = Request.params ("ContentType"). Tostring
Response.WriteFile (Strlink)
Response.End ()
The file name can be read from the data, directly specified to the server's path, so require the upload file ' requirements specified file on the server to save the path.
For this method, you need to redirect to a page that is responsible for processing the write of the file. Parameter contenttype can choose to write or not write, in the clear case, it is best to write.
But Appendheader must specify that the last call WriteFile the file output, the path used is the relative path.
11. How to make the client script work when the control is dynamically loaded
Event.srcelement, you can get the event initiator object. When you want to refer to multiple objects, you can save the value of the control with a variable.
The method is as follows:
Response.Write ("<input type=\" hidden\ "id=\" jjj\ "value=" +this. Clientid+ ">");
Note: The ID number of this control here is a fixed value.
12. How to register the ASPNET on IIS
Aspnet_regiis-i
13. Server Objects
1) Server.Transfer: Go to another page, but do not send any information to the browser, when the user refreshes, will refresh is the page before the redirect.
2) Server.Execute: Executes another page request, after execution returns the original page.
14, disable the method of request verification
The request validation process detects a potentially dangerous client input value and the processing of the request has been aborted. This value may indicate an attempt to compromise the security of an application, such as a cross-site scripting attack. You can disable request validation by setting Validaterequest=false in the Page directive or configuration section. However, in this case, it is strongly recommended that the application explicitly check all input.
such as:<system.web>
<pages validaterequest= "false"/>
</system.web>