WebForm---additions and deletions to search

Source: Internet
Author: User

---restore content starts---

first, add

Front code:

<body> <form id="Form1"runat="Server"> User Name:<asp:textbox id="TextBox1"runat="Server"></asp:textbox><br/><br/>password:<asp:textbox id="TextBox3"runat="Server"Textmode="Password"></asp:textbox><br/><br/>Confirm Password:<asp:textbox id="TextBox4"runat="Server"Textmode="Password"></asp:textbox><br/><br/>nickname:<asp:textbox id="TextBox6"runat="Server"></asp:textbox><br/><br/>gender:<asp:radiobuttonlist id="RadioButtonList1"runat="Server"repeatdirection="Horizontal"repeatlayout="Flow"> <asp:listitem value="true"Selected="True"> Men </asp:ListItem> <asp:listitem value="false"> Women </asp:ListItem> </asp:radiobuttonlist><br/><br/>birthday:<asp:dropdownlist id="DropDownList2"runat="Server"></asp:DropDownList> year <asp:dropdownlist id="DropDownList3"runat="Server"></asp:DropDownList> month <asp:dropdownlist id="DropDownList4"runat="Server"></asp:DropDownList> Day <br/><br/>ethnicity:<asp:dropdownlist id="DropDownList1"runat="Server"Width="122px"></asp:dropdownlist><br/><br/> <asp:button id="Button1"runat="Server"text="Register"/><br/> <asp:label id="Label1"runat="Server"text=""></asp:Label> </form></body>
View Code

Need to operate on gender, birthday, ethnicity, password:

1. gender: default check: <asp:listitem value= "true" selected= "true" > Male </asp:ListItem>

2. Birthday 3, nationality:

 protected voidPage_Load (Objectsender, EventArgs E) {        if(! IsPostBack)//Data Binding        {             for(inti = DateTime.Now.Year; I >=1900; i--)            {                //Add the year, create a listitem, Let it build one at a time per cycleListItem Li =NewListItem (i.tostring (), i.tostring ());            DROPDOWNLIST2.ITEMS.ADD (li); }             for(inti =1; I <= a; i++)            {                //MonthListItem Li =NewListItem (i.tostring (), i.tostring ());            DROPDOWNLIST3.ITEMS.ADD (li); }             for(inti =1; I <= to; i++)            {                //DayListItem Li =NewListItem (i.tostring (), i.tostring ());            DROPDOWNLIST4.ITEMS.ADD (li); }            //take out the national dataDropdownlist1.datasource =NewNationda ().            Select (); Dropdownlist1.datatextfield="Nationname"; Dropdownlist1.datavaluefield="Nationcode";        Dropdownlist1.databind (); }            }

4. Password:

JS authentication A Click Add button, if two times the password input inconsistent, Click the Add button does not refresh the page, first in the foreground to determine the password box after adding a lable, to display

JS written in the Head:

<script type="Text/javascript">window.onload= function () {/*Document Action take out the contents of the Password box*/document.getElementById ("Button1"). onclick =function () {varPWD1 = document.getElementById ("TextBox3"). value; varPWD2 = document.getElementById ("TextBox4"). value; /*alert (pwd1); Check it.*/               /*Alert (pwd2);*/                if(pwd1! =Pwd2) {document.getelementbyid ("Label2"). InnerText ="two times password input inconsistency"; return false;/*password to prevent refresh, just like refresh*/                }            };    }; </script> <style type="Text/css">#Label2 {color:red;/*the text displayed in the Label2 is red .*/        }    </style>

Click the Add button to populate the database with the added content and to display it in the Interface. Add a total of 4 steps in the Click Event.

In the data manipulation class, do an added method:

  public BOOLInsert (Users U) {//Add        BOOLisOK =false; Cmd.commandtext="INSERT INTO Users values (@a,@b,@c,@d,@e,@f)"; Cmd.        Parameters.clear (); Cmd. Parameters.Add ("@a", u.username); Cmd. Parameters.Add ("@b", u.password); Cmd. Parameters.Add ("@c", u.nickname); Cmd. Parameters.Add ("@d", u.sex); Cmd. Parameters.Add ("@e", u.birthday); Cmd. Parameters.Add ("@f", u.nation); Conn.        Open (); Try{cmd.            ExecuteNonQuery (); isOK=true; }        Catch{} Conn.        Close (); returnisok; }
View Code

<a href= "zhuce.aspx" target= "_blank"> Add user </a> Hyperlink to the registration screen and open a new page page;

Response.Write ("<script>this. Opener. location.href= ' main.aspx '; this.close ();</script> "); Finish adding points OK closes the current page, displays the home page, and Refreshes.

    voidButton1_Click (Objectsender, EventArgs E)//Delegate    {       //1. Build a Users ObjectUsers U =NewUsers (); U.username=textbox1.text; U.password=textbox3.text; U.nickname=textbox6.text; U.sex=Convert.toboolean (RadioButtonList1.SelectedItem.Value); stringData=dropdownlist2.selectedvalue+"-"+dropdownlist3.selectedvalue+"-"+dropdownlist4.selectedvalue; U.birthday=Convert.todatetime (data); U.nation=DropDownList1.SelectedItem.Value; //2, Add this object to the database, first add the method in Userda        BOOLOK =NewUSERSDA ().        Insert (u); //3. Prompt to add success        if(ok) {response.write ("<script>alert (' Add success! ') </script>"); Response.Write ("<script>this.opener.location.href= ' main.aspx '; this.close ();</script>"); //Response.Redirect ("main.aspx");//re-set Items                    }        Else{response.write ("<script>alert (' Add failed! ') </script>"); }        //4. Close this page to refresh the display page//Write with JS    }   

Main Code:

<input id="BTN1"Type="Button"Value="Add User"/> Add button <script>document.getElementById ("BTN1"). onclick =function () {window.open ("zhuce.aspx", "_blank" ); Open a new page }; Click the Add button to add the Page.</script> </form></body>

second, Delete

---restore content ends---

WebForm---additions and deletions to search

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.