DataBoundControlAdapter.PerformDataBinding(IEnumerable) Metoda
Definicja
Ważne
Niektóre informacje odnoszą się do produktu w wersji wstępnej, który może zostać znacząco zmodyfikowany przed wydaniem. Firma Microsoft nie udziela żadnych gwarancji, jawnych lub domniemanych, w odniesieniu do informacji podanych w tym miejscu.
Wiąże dane w źródle danych skojarzonego DataBoundControl obiektu z adapterem sterującym.
protected public:
virtual void PerformDataBinding(System::Collections::IEnumerable ^ data);
protected internal virtual void PerformDataBinding(System.Collections.IEnumerable data);
abstract member PerformDataBinding : System.Collections.IEnumerable -> unit
override this.PerformDataBinding : System.Collections.IEnumerable -> unit
Protected Friend Overridable Sub PerformDataBinding (data As IEnumerable)
Parametry
- data
- IEnumerable
Element IEnumerable z wartością Object , która ma być powiązana z pochodną DataBoundControl.
Przykłady
Poniższy przykład kodu pokazuje, jak zastąpić PerformDataBinding kolekcję, aby zapisać źródło danych w obiekcie jednowymiarowym ArrayList i dodać separatory wierszy. Pokazano również, jak zastąpić metodę RenderContents renderowania ArrayList obiektu jako listę pól rozdzielonych <br />
tagami.
// One-dimensional list for the grid data.
ArrayList dataArray = new ArrayList();
// Copy grid data to one-dimensional list, add row separators.
protected override void PerformDataBinding(IEnumerable data)
{
IEnumerator dataSourceEnumerator = data.GetEnumerator();
// Iterate through the table rows.
while (dataSourceEnumerator.MoveNext())
{
// Add the next data row to the ArrayList.
dataArray.AddRange(
((DataRowView)dataSourceEnumerator.Current).Row.ItemArray);
// Add a separator to the ArrayList.
dataArray.Add("----------");
}
}
// Render the data source as a one-dimensional list.
protected override void RenderContents(
System.Web.UI.HtmlTextWriter writer)
{
// Render the data list.
for( int col=0; col<dataArray.Count;col++)
{
writer.Write(dataArray[col]);
writer.WriteBreak();
}
}
' One-dimensional list for the grid data.
Private dataArray As New ArrayList()
' Copy grid data to one-dimensional list, add row separators.
Protected Overrides Sub PerformDataBinding(ByVal data As IEnumerable)
Dim dataSourceEnumerator As IEnumerator = data.GetEnumerator()
' Iterate through the table rows.
While dataSourceEnumerator.MoveNext()
' Add the next data row to the ArrayList.
dataArray.AddRange(CType(dataSourceEnumerator.Current, _
DataRowView).Row.ItemArray)
' Add a separator to the ArrayList.
dataArray.Add("----------")
End While
End Sub
' Render the data source as a one-dimensional list.
Protected Overrides Sub RenderContents( _
ByVal writer As System.Web.UI.HtmlTextWriter)
' Render the data list.
Dim col As Integer
For col = 0 To dataArray.Count - 1
writer.Write(dataArray(col))
writer.WriteBreak()
Next col
End Sub
Uwagi
Metoda PerformDataBinding jest wywoływana zamiast DataBoundControl.PerformDataBinding metody, gdy DataBoundControlAdapter adapter sterujący jest dołączony do kontrolki pochodzącej DataBoundControl z klasy.
Zazwyczaj przesłonięć iterowanie danych, tworzenie odrębnych DataBoundControl.PerformDataBinding nazw i wartości w razie potrzeby oraz zapisywanie ich w wewnętrznej kolekcji. RenderContents Zazwyczaj lub podobna metoda DataBoundControl metody spowoduje wypełnienie interfejsu użytkownika lub kontrolek podrzędnych z tej kolekcji wewnętrznej.
Uwagi dotyczące dziedziczenia
Zastąpij metodę PerformDataBinding(IEnumerable) , gdy dla przeglądarki docelowej jest wymagana wyspecjalizowana logika powiązania — na przykład gdy nazwy elementów muszą być konstruowane inaczej niż w przypadku ogólnego użycia kontrolki.
Metoda podstawowa PerformDataBinding(IEnumerable) wywołuje metodę PerformDataBinding(IEnumerable). Metodę podstawową PerformDataBinding(IEnumerable) należy wywołać tylko wtedy, gdy wymagana jest funkcja powiązania danych elementu DataBoundControl.