Read the database data and control the display length!

xiaoxiao2021-03-05  21

Public void bindgrid ()

{

OLEDBCONNECTION myconnection = CN;

DataSet DS = New DataSet ();

OLEDBDataAdapter Adapter = New OLEDBDataAdapter ("SELECT TITE, CREATEDATEDATAADAPTER);

Adapter.Fill (DS, "Document");

//

For (int i = 0; i

{

IF (ds.tables [0] .ROWS [i] ["title"]. Tostring (). Length> 6)

DS.Tables [0] .ROWS [I] ["Title"] = cutstring (ds.tables [0] .rows [i] ["title"]. Tostring (), 6);

}

MyDataGrid.datasource = ds.tables ["document"]. DefaultView;

MyDataGrid.databind ();

Showstats ();

}

#Region string intercept function

Public Static String Cutstring (String InputString, INT LEN)

{

Asciiencoding ascii = new asciiencoding (); int Templen = 0; string tempstring = ""; byte [] s = ascii.getbytes (InputString); for (int i = 0; i

If (Templen> Len) Break;} // If you cut, add half a omitted number byte [] mybyte = system.text.encoding.default.getBytes (InputString); if (mybyte.length> len) Tempstring = "... "

Return Tempstring;} #ENDREGION

My method is that after reaching a certain length, taking the binder string, when the mouse moves to top, displaying all content. private void dgAll_ItemDataBound (object sender, System.Web.UI.WebControls.DataGridItemEventArgs e) {if (e.Item.ItemType! = ListItemType.Header && e.Item.ItemType! = ListItemType.Footer) {e.Item.Cells [ 0] .attributes.add ("onMousemove", "JavaScript: moveinfo ();"); E.Item.cells [0] .attributes.add ("OnMouseOver", "JavaScript: showinfo (this, '" e. Item.cells [0] .text "','" E.Item.cells [2] .text "','" E.Item.cells [3] .Text ");"); E.Item.cells [0] .attributes.add ("onmouseout", "JavaScript: clearinfo ();"); if (E.Item.cells [0] .Text.gength> 4) {E.Item.cells [0] .Text = E.Item.cells [0] .text.substring (0,4) "...";} if (E.Item.cells [2] .Text.length> 4) {e .Item.cells [2] .text = E.Item.cells [2] .text.substring (0, 4) "...";}}} I feel that your code is complicated, I will give me Method PUBLIC STRING STRCUT (String Str, INT Length) {String Str = Str; IF (Str.Length

转载请注明原文地址:https://www.9cbs.com/read-39364.html

New Post(0)