Visual Basic Power Packs
DataRepeater..::.DrawItem Event

Occurs when a DataRepeaterItem must be drawn.

Namespace:  Microsoft.VisualBasic.PowerPacks
Assembly:  Microsoft.VisualBasic.PowerPacks.Vs (in Microsoft.VisualBasic.PowerPacks.Vs.dll)
Syntax

Visual Basic (Declaration)
Public Event DrawItem As DataRepeaterItemEventHandler
Visual Basic (Usage)
Dim instance As DataRepeater
Dim handler As DataRepeaterItemEventHandler

AddHandler instance.DrawItem, handler
C#
public event DataRepeaterItemEventHandler DrawItem
Visual C++
public:
 event DataRepeaterItemEventHandler^ DrawItem {
    void add (DataRepeaterItemEventHandler^ value);
    void remove (DataRepeaterItemEventHandler^ value);
}
JScript
JScript does not support events.
Remarks

Use this event to change the appearance of DataRepeaterItem objects as they are scrolled into view.

At run time, appearance-related properties can be set based on conditions as each item is scrolled into view. For example, in a scheduling application, you might change the background color of an item to warn users when an item is past due. If you set a property in a conditional statement such as If…Then, you must also use an Else clause to specify the appearance when the condition is not met.

For more information about how to handle events, see Consuming Events.

Examples

Some common customizations for the DataRepeater control include displaying the rows in alternating colors and changing the color of a field based on a condition. The following example shows how to perform these customizations. This example assumes that you have a DataRepeater control that is bound to the Products table in the Northwind database.

Visual Basic
Private Sub DataRepeater1_DrawItem(ByVal sender As Object, ByVal e _
 As Microsoft.VisualBasic.PowerPacks.DataRepeaterItemEventArgs) _
 Handles DataRepeater1.DrawItem
    ' Alternate the back color.
    If (e.DataRepeaterItem.ItemIndex Mod 2) <> 0 Then
        ' Apply the secondary back color.
        e.DataRepeaterItem.BackColor = Color.AliceBlue
    Else
        ' Apply the default back color.
        DataRepeater1.ItemTemplate.BackColor = Color.White
    End If
    ' Change the color of out-of-stock items to red.
    If e.DataRepeaterItem.Controls(UnitsInStockTextBox.Name).Text _
     < 1 Then
        e.DataRepeaterItem.Controls(UnitsInStockTextBox.Name). _
         BackColor = Color.Red
    Else
        e.DataRepeaterItem.Controls(UnitsInStockTextBox.Name). _
         BackColor = Color.White
    End If
End Sub
C#
private void dataRepeater1_DrawItem(object sender, 
    Microsoft.VisualBasic.PowerPacks.DataRepeaterItemEventArgs e)
{
    // Alternate the back color.
    if ((e.DataRepeaterItem.ItemIndex % 2) != 0)
    // Apply the secondary back color.
    {
        e.DataRepeaterItem.BackColor = Color.AliceBlue;
    }
    else
    {
        // Apply the default back color.
        dataRepeater1.ItemTemplate.BackColor = Color.White;
    }
    // Change the color of out-of-stock items to red.
    if (e.DataRepeaterItem.Controls["unitsInStockTextBox"].Text == "0")
    {
        e.DataRepeaterItem.Controls["unitsInStockTextBox"].BackColor = Color.Red;
    }
    else
    {
        e.DataRepeaterItem.Controls["unitsInStockTextBox"].BackColor = Color.White;
    }
}
Permissions

See Also

Reference

Other Resources

Tags :


Page view tracker