ASP. NET project notes (1)

Source: Internet
Author: User

1. Deep copy and shortest copy of datatable

Assume that a datatable object table is known.

 
Datatable copydatatable; copydatatable = table. Copy (); // copy the structure and data of the datatable. Copydatatable = table; // a copy is a reference.

 

2. deduplication of datatable

Assume that a datatable object table is known. It has three columns: column1, column2, and column3. And the data of this able is not obtained from the database. So how can we remove the duplicate data in this able?

The method is as follows:

 
Dataview = new dataview (table); datatable = dataview. totable (true, new string [] {"column1", "column2", "column3 "});

 

3. Obtain the text value of the server control set to readonly.

Take textbox as an example. For example, <asp: textbox id = "txtinfo" runat = "server" readonly = "true"> </ASP: textbox>, although this control can be assigned a value through JS. CS file txtinfo. the text value is always a null string.

Solution:

Instead of using the readonly attribute of the server control, txtinfo is used in page_load. attributes ["readonly"] = "true"; implements readonly, and then uses txtinfo. text to get the value of text.

 

4. How to achieve the effect of page blackening during page loading

Method 1: Use blockui plugin of jquery.

Method 2: Use the following HTML and control its display with Js.

HTML + CSS to achieve this effectCode:

 
<Div id = "fadediv" style = "Z-index: 100; position: absolute; display: none; width: 100%; Height: 1000px; Background-color: #0060c0; filter: alpha (opacity = 20); text-align: center; ">  </div>
JS method:
 
Document. getelementbyid ("fadediv"). style. Display = "Block"; // display document. getelementbyid ("fadediv"). style. Display = "NONE"; // hide

 

5. Obtain the selected values (Value and text) in the select box) Select Server Control:

<Select id = "select1" runat = "server">
<Option value = "1" selected = "selected"> 1 </option>
<Option value = "2"> 2 </option>
</SELECT>

C # method:

 
String strvalue = select1.value; // The value is "1" (that is, the value) string strtext = select1.items [select1.selectedindex]. tostring (); // The value is "1" (that is, the text value)

JS method:

 
VaR selectobj = document. getelementbyid ("select1"); var strvalue = selectobj. value; // The value is "1" (that is, the value) var strtext = selectobj. options (selectobj. selectedindex ). text; // The value is "1" (that is, the text value)

Jquery method:

 
$ ("# Select1 "). val (); // The value is "1" (value) $ ("# select1 option: Selected "). val (); // The value is "1" (value) $ ("# select1> Option: Selected "). get (0 ). text; // The value is "1" (that is, the text value)

 

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.