asp.net in the DataGrid double row Cross list head design experience!

Source: Internet
Author: User

asp.net the DataGrid double row Cross list header design experience.
One, the DataGrid's property settings
1. Allowpaging:true
2. Pagestyle->position:topandbottom
3. Optional: Pagestyle->horizonalign:center (make text centered)
4. Optional:itemstyle-> Horizonalign:center (center text)
Two, code part
1. First, make the DataGrid bind 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); The
DataSet ds=new DataSet ();
da. Fill (ds, "gr");
Dggeren.datasource=ds. Tables["GR"]. DefaultView;
Dggeren.databind ();


}
2. Add the handler function for the ItemCreated event for the DataGrid,
3. In order to determine the position of the two (up and down) pager 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 handler function for 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;//Text to the center

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";

It could be: 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= "floor number";

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
}

}

}

Shielding Ctrl-v


The TextBox control in WinForm has no way to mask the ctrl-v clipboard paste action, if you need an input box, but you do not want the user to paste the contents of the Clipboard, you can use the RichTextBox control instead, and the CTRL-V key is masked in KeyDown, example:

private void Richtextbox1_keydown (object sender, System.Windows.Forms.KeyEventArgs e)
{
if (E.control & E.KEYCODE==KEYS.V)
E.handled = true;
}

--------------------------------------------------------------------------------

Panel horizontal scrolling, vertical automatic expansion

Return to Tab

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

The DataGrid row changes color 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 "+"/"");
}
}

Change the selection of columns to achieve either a full or a full selection.
protected void Checkall_checkedchanged (object sender, System.EventArgs e)
{
CheckBox Chkexport;
if (checkall.checked)
{
foreach (DataGridItem odatagriditem in Mydatagrid.items)
{
Chkexport = (checkbox) Odatagriditem.findcontrol ("Chkexport");
Chkexport.checked = true;
}
}
Else
{
foreach (DataGridItem odatagriditem in Mydatagrid.items)
{
Chkexport = (checkbox) Odatagriditem.findcontrol ("Chkexport");
chkexport.checked = false;
}
}
}
Number formatting

"<% #Container. DataItem (" price ")%> result is 500.0000, how to format into 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")%>

Displayed as: 2004-8-11 19:44:28

I only want: 2004-8-11 "
<%# DataBinder.Eval (Container.DataItem, "company_ureg_date", "{0:yyyy-m-d}")%>


How to make a connection to the hyperlinkcolumn generated, click on the connection, open a new window.

  

HyperLinkColumn has a property target that sets the value of the device to "_blank". (target= "_blank")

The DataGrid selects the row below, why always refresh, and then scroll to the top, just the selected line due to the screen relationship can not see.

Page_Load
Page.smartnavigation=true


Modify the data in the DataGrid, when you click on the edit key, the data appears in the text box, how to control the size of the text box?

private void Datagrid1_itemdatabound (obj Sender,datagriditemeventargs e)
{
for (int i=0;i if (E.item.itemtype==listitemtype.edittype)
{
E.item.cells[i]. Attributes.Add ("Width", "80px")
}
}

The

asp.net multiple-line textbox increases automatically with the content increase without the scroll bar displayed.

Related Article

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.