本文整理汇总了C#中System.Web.UI.WebControls.GridViewRow.DataBind方法的典型用法代码示例。如果您正苦于以下问题:C# GridViewRow.DataBind方法的具体用法?C# GridViewRow.DataBind怎么用?C# GridViewRow.DataBind使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.UI.WebControls.GridViewRow
的用法示例。
在下文中一共展示了GridViewRow.DataBind方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InitializeRow
private void InitializeRow(GridViewRow row, DataControlField[] fields, TableRowCollection newRows)
{
var e = new GridViewRowEventArgs(row);
InitializeRow(row, fields);
OnRowCreated(e);
newRows.Add(row);
row.DataBind();
OnRowDataBound(e);
row.DataItem = null;
}
示例2: CreateChildControls
protected override int CreateChildControls (IEnumerable data, bool dataBinding)
{
// clear GridView
Controls.Clear ();
table = null;
rows = null;
if (data == null) {
return 0;
}
PagedDataSource dataSource;
if (dataBinding) {
DataSourceView view = GetData ();
dataSource = new PagedDataSource ();
dataSource.DataSource = data;
if (AllowPaging) {
dataSource.AllowPaging = true;
dataSource.PageSize = PageSize;
if (view.CanPage) {
dataSource.AllowServerPaging = true;
if (SelectArguments.RetrieveTotalRowCount)
dataSource.VirtualCount = SelectArguments.TotalRowCount;
}
if (PageIndex >= dataSource.PageCount)
pageIndex = dataSource.PageCount - 1;
dataSource.CurrentPageIndex = PageIndex;
}
PageCount = dataSource.PageCount;
}
else
{
dataSource = new PagedDataSource ();
dataSource.DataSource = data;
if (AllowPaging) {
dataSource.AllowPaging = true;
dataSource.PageSize = PageSize;
dataSource.CurrentPageIndex = PageIndex;
}
}
bool createPager = AllowPaging && (PageCount >= 1) && PagerSettings.Visible;
ArrayList list = new ArrayList ();
// Creates the set of fields to show
_dataEnumerator = null;
ICollection fieldCollection = CreateColumns (dataSource, dataBinding);
int fieldCount = fieldCollection.Count;
DataControlField dcf;
DataControlField[] fields = new DataControlField [fieldCount];
fieldCollection.CopyTo (fields, 0);
for (int i = 0; i < fieldCount; i++) {
dcf = fields [i];
dcf.Initialize (AllowSorting, this);
if (EnableSortingAndPagingCallbacks)
dcf.ValidateSupportsCallback ();
}
bool skip_first = false;
IEnumerator enumerator;
if (_dataEnumerator != null) {
// replaced when creating bound columns
enumerator = _dataEnumerator;
skip_first = true;
}
else {
enumerator = dataSource.GetEnumerator ();
}
// Main table creation
while (skip_first || enumerator.MoveNext ()) {
skip_first = false;
object obj = enumerator.Current;
if (list.Count == 0) {
if (createPager && (PagerSettings.Position == PagerPosition.Top || PagerSettings.Position == PagerPosition.TopAndBottom)) {
topPagerRow = CreatePagerRow (fieldCount, dataSource);
OnRowCreated (new GridViewRowEventArgs (topPagerRow));
ContainedTable.Rows.Add (topPagerRow);
if (dataBinding) {
topPagerRow.DataBind ();
OnRowDataBound (new GridViewRowEventArgs (topPagerRow));
}
if (PageCount == 1)
topPagerRow.Visible = false;
}
GridViewRow headerRow = CreateRow (-1, -1, DataControlRowType.Header, DataControlRowState.Normal);
InitializeRow (headerRow, fields);
OnRowCreated (new GridViewRowEventArgs (headerRow));
ContainedTable.Rows.Add (headerRow);
if (dataBinding) {
headerRow.DataBind ();
OnRowDataBound (new GridViewRowEventArgs (headerRow));
//.........这里部分代码省略.........
示例3: CreateChildControls
protected override int CreateChildControls(IEnumerable dataSource, bool dataBinding)
{
int rows = base.CreateChildControls(dataSource, dataBinding);
// no data rows created, create empty table if enabled
if (rows == 0 && (ShowFooterWhenEmpty || ShowHeaderWhenEmpty))
{
// create the table
Table table = CreateChildTable();
Controls.Clear();
Controls.Add(table);
DataControlField[] fields;
if (AutoGenerateColumns)
{
var source = new PagedDataSource { DataSource = dataSource };
ICollection autoGeneratedColumns = CreateColumns(source, true);
fields = new DataControlField[autoGeneratedColumns.Count];
autoGeneratedColumns.CopyTo(fields, 0);
}
else
{
fields = new DataControlField[Columns.Count];
Columns.CopyTo(fields, 0);
}
TableRowCollection newRows = table.Rows;
if (ShowHeaderWhenEmpty)
{
// create a new header row
_headerRow = CreateRow(-1, -1, DataControlRowType.Header, DataControlRowState.Normal);
InitializeRow(_headerRow, fields, newRows);
}
// create the empty row
GridViewRow emptyRow = new GridViewRow(-1, -1, DataControlRowType.EmptyDataRow, DataControlRowState.Normal);
TableCell cell = new TableCell();
List<DataControlField> f = fields.Where(dataControlField => dataControlField.Visible).ToList();
cell.ColumnSpan = f.Count;
//cell.Width = Unit.Percentage(100);
// respect the precedence order if both EmptyDataTemplate
// and EmptyDataText are both supplied ...
if (EmptyDataTemplate != null)
{
EmptyDataTemplate.InstantiateIn(cell);
}
else if (!string.IsNullOrEmpty(EmptyDataText))
{
cell.Controls.Add(new LiteralControl(EmptyDataText));
}
emptyRow.Cells.Add(cell);
GridViewRowEventArgs e = new GridViewRowEventArgs(emptyRow);
OnRowCreated(e);
newRows.Add(emptyRow);
emptyRow.DataBind();
OnRowDataBound(e);
emptyRow.DataItem = null;
if (ShowFooterWhenEmpty && ShowFooter)
{
// create footer row
_footerRow = CreateRow(-1, -1, DataControlRowType.Footer, DataControlRowState.Normal);
InitializeRow(_footerRow, fields, newRows);
newRows.Remove(emptyRow);
}
}
return rows;
}