ItemDATABOUND small knot

xiaoxiao2021-03-06  112

In DataGrid, if you want to format or modify some records, it is more convenient to use ItemDatabase.

For example, to show that someone's deposit amount has been less than some amount, and use red to display, etc.. ItemDatabase occurs

After the data is bound to the DataGrid, the content is sent to the client. such as

Private void onItemDatabase (Object Sender,

System.Web.ui.WebControls.DataGriditeMeventargs E)

{

// Check if the current row contacts items; if it's

// a header or footer row this will throw an error

IF (E.Item.ItemType == ListItemType.Item ||

E.Item.ItemType == ListItemType.alternatingItem)

{

// Get a copy of the "dglabel2" label That Contains the

// "Balance" Value

Label lblbalance = (label) E.Item.FindControl ("DGlabel2");

// convert the value contained in the label to a double type

Double dblbalance = Convert.Todouble (lblbalance.text);

// if That Numeric Value Is NEGATIVE

IF (dblbalance <0)

// ... display it in red

E.Item.cells [3]. manufacture = system.drawing.color.red;

// Get a copy of the "dglabel1" label That Contains the

// "country" Value

Label lblcountry = (label) E.Item.FindControl ("DGlabel1");

// ... Convert it to a string

String strcountry = lblcountry.text;

// if it's a north american country ...

IF (strcountry == "usa" ||

STRCOUNTRY == "MEXICO" ||

STRCOUNTRY == "canada")

{

// get a copy of the "dglabel0" label That Contains the

// "Customerid" Value, We'll Use it is query string

// for the popup

Label lblid = (label) E.Item.FindControl ("DGlabel0");

// ... Convert it to a string

String strid = lblid.text;

// Replace the "country" value displayed in the datagrid

// with "jamaica", Placed in a Hyperlink Who's onclick // Event Calls a javascript "popup" Window

E.Item.cells [2] .text = " jamaica

}

}

}

Itemcreated events and it is somewhat, Itemcreated occurs before the ItemDatabase event, when each item in DataGrid is created but no

When there is data, it cannot be modified or read with itemcreated events.

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

New Post(0)