N skills in ASP. NET Design

Source: Internet
Author: User

[Switch] ASP. NET development tips
 
Horizontal scrolling of the panel and Automatic Vertical Scaling
<Asp: Panel style = "overflow-X: Scroll; overflow-Y: auto;"> </ASP: Panel>

Press enter to convert to Tab

<Script language = "JavaScript" for = "document" event = "onkeydown">
If (event. keycode = 13 & event. srcelement. type! = 'Button '& event. srcelement. type! = 'Submit '& event. srcelement. type! = 'Reset' & event. srcelement. type! = ''& Event. srcelement. type! = 'Textea ');
Event. keycode = 9;
</SCRIPT>

Onkeydown = "If (event. keycode = 13) event. keycode = 9"

The row color of the DataGrid changes with the mouse

Private void dgzf_itemdatabound (Object sender, system. Web. UI. webcontrols. datagriditemeventargs E)
{
If (E. Item. itemtype! = Listitemtype. header)
{
E. item. attributes. add ("onmouseout", "this. style. backgroundcolor = \ "" + E. item. style ["background-color"] + "\"");
E. Item. Attributes. Add ("onmouseover", "This. style. backgroundcolor = \" "+" # eff3f7 "+ "\"");
}
}

Select All or all columns.
Protected void checkall_checkedchanged (Object sender, system. eventargs E)
{
Checkbox chkexport;
If (checkall. Checked)
{
Foreach (maid in mydatagrid. Items)
{
Chkexport = (checkbox) odatagriditem. findcontrol ("chkexport ");
Chkexport. Checked = true;
}
}
Else
{
Foreach (maid in mydatagrid. Items)
{
Chkexport = (checkbox) odatagriditem. findcontrol ("chkexport ");
Chkexport. Checked = false;
}
}
}
Number formatting

The result of <% # container. dataitem ("price") %> is 500.0000. How to format it to 500.00 ?]

<% # Container. dataitem ("price", "{0: ¥ #,## 0.00}") %>

Int I = 123456;
String S = I. tostring ("###,##. 00 ");

Date formatting

[ASPX page: <% # databinder. eval (container. dataitem, "company_ureg_date") %>

Shown as: 19:44:28

I only want]
<% # Databinder. eval (container. dataitem, "company_ureg_date", "{0: yyyy-m-d}") %>

After connecting to the connection generated by hyperlinkcolumn, click Connect to open a new window?

Hyperlinkcolumn has a property target, which can be set to "_ blank" (target = "_ blank ")

Why do we always refresh the row selected at the bottom of the DataGrid, and then scroll to the top, the selected row cannot be seen due to the relationship between the screen.

Page_load
Page. smartnavigation = true

Modify data in the DataGrid. When you click the edit key, the data appears in the text box. How do I control the size of the text box?

Private void maid (OBJ sender, maid E)
{
For (INT I = 0; I <E. Item. cells. Count-1; I ++)
If (E. Item. itemtype = listitemtype. edittype)
{
E. Item. cells [I]. Attributes. Add ("width", "80px ")
}
}

Asp.net's multi-row textbox increases automatically with the increase of content without displaying the scroll bar!

<TD align = "center" valign = "TOP">
<Asp: textbox id = "txtnews" runat = "server textmode =" multiline "readonly = true width = 100% wrap =" true "style =" overflow-Y: visible "> </textbox>
</TD>

[Original] experience in cross-list header design of DataGrid in Asp.net!
1. DataGrid attribute settings
1. allowpaging: True
2. pagestyle-> position: topandbottom
3. Optional: pagestyle-> horizonalign: Center (center text)
4. Optional: itemstyle-> horizonalign: Center (center text)
II,CodePart
1. First bind the DataGrid to a table in the database, for example:
Private void page_load (Object sender, system. eventargs E)
{
// Place user code here to initialize the page
If (! Ispostback)
{
Sqlconnection myconn = new sqlconnection ("Server = localhost; uid = sa; Pwd = sa; database = db_test ");
Sqldataadapter da = new sqldataadapter ("select * from individual", myconn );
Dataset DS = new dataset ();
Da. Fill (DS, "GR ");
Dggeren. datasource = Ds. Tables ["GR"]. defaultview;
Dggeren. databind ();

}
2. Add the itemcreated event handler for the DataGrid,
3. To determine the two (up and down) pager locations in the DataGrid, we can use a global variable to determine.
Define a global variable private int m_createpagetimes = 0;
4. add content to the processing function of the itemcreated event of the DataGrid as follows:
Private void dggeren_itemcreated (Object sender, system. Web. UI. webcontrols. datagriditemeventargs E)
{
Switch (E. Item. itemtype)
{
// Case (listitemtype. pager ):
Case listitemtype. Pager:
{
If (m_createpagetimes = 0)
{
Datagriditem ROW = (datagriditem) E. item;
Row. cells. Clear ();

// Row. backcolor = color. Navy; // background color
// Row. forecolor = color. Red; // foreground color

Row. horizontalalign = horizontalalign. Center; // center the text

Tablecell cell0 = new tablecell ();
Cell0.rowspan = 2;
Cell0.controls. Add (New literalcontrol ("name "));

Tablecell cell1 = new tablecell ();
Cell1.columnspan = 2; // The default columnspan value is 1.
Cell1.text = "housing address information ";

// You can also do this: cell1.controls. Add (New literalcontrol ("housing address information "));

// Tablecell cell2 = new tablecell ();
// Cell2.controls. Add (New literalcontrol (""));
Tablecell cell2 = new tablecell ();
Cell2.rowspan = 2;
Cell2.text = "Date of Birth ";

Row. cells. Add (cell0 );
Row. cells. Add (cell1 );
Row. cells. Add (cell2 );

M_createpagetimes ++;
}
Break;
}
Case listitemtype. header:
{
Datagriditem head = (datagriditem) E. item;
Head. cells. Clear ();

// Head. verticalalign = verticalalign. Middle;
// Head. horizontalalign = horizontalalign. Center;

// Tablecell cell00 = new tablecell ();
// Cell00.rowspan = 2;
// Cell00.text = "name ";

Tablecell cell01 = new tablecell ();
Cell01.text = "Building No ";

Tablecell cell02 = new tablecell ();
Cell02.text = "room number ";

// Tablecell cell03 = new tablecell ();
// Cell03.text = "Date of Birth ";

// Head. cells. Add (cell00 );
Head. cells. Add (cell01 );
Head. cells. Add (cell02 );
// Head. cells. Add (cell03 );
Break;
}

}

}

Shielded CTRL-V

The Textbox Control in winform has no way to block the clipboard pasting action for the CTRL-V. If you need an input box but do not want the user to paste the clipboard content, you can use the RichTextBox Control instead, and shield the CTRL-V key in keydown, for example:

Private void richtextbox1_keydown (Object sender, system. Windows. Forms. keyeventargs E)
{
If (E. Control & E. keycode = keys. V)
E. Handled = true;
}

 

 

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.