他の要因に応じて、ButtonFieldのテキストの値を変更したいと思います。いくつかのコード:
public override void InitializeCell(DataControlFieldCell cell, DataControlCellType cellType, DataControlRowState rowState, int rowIndex)
{
base.InitializeCell(cell, cellType, rowState, rowIndex);
bool isDataRowAndIsHighlightFieldSpecified = cellType == DataControlCellType.DataCell && !string.IsNullOrEmpty(UnnpiFlagField);
if (isDataRowAndIsHighlightFieldSpecified)
{
cell.DataBinding += new EventHandler(cell_DataBinding);
}
}
private void cell_DataBinding(object sender, EventArgs e)
{
TableCell cell = (TableCell)sender;
object dataItem = DataBinder.GetDataItem(cell.NamingContainer);
IButtonControl button = cell.Controls[0] as IButtonControl;
button.Text = DataBinder.GetPropertyValue(dataItem, DataTextField).ToString();
bool highlightTheText = DataBinder.GetPropertyValue(dataItem, IsFlagField).ToString().ToUpper() == "Y";
if (highlightTheText)
{
cell.CssClass = string.Concat(ItemStyle.CssClass, " thisChangesFine");
button.Text = "CHANGE ME";
}
}
このコードは、セルのテキストが変更されて強調表示されるBoundFieldに最適ですが、ボタンコントロールには、aspxページで正しいCommandNameが設定されたボタンが実際にありますが、Text値には最初は何も含まれておらず、別の場所に設定されているようです。 。ここで別の値に設定すると、別の場所で元の値にリセットされているようです。リフレクターを調べてみると、これがどこで起こっているのかわかりません。リフレクターショー:
protected override DataControlField CreateField()
public override bool Initialize(bool sortingEnabled, Control control)
private void OnDataBindField(object sender, EventArgs e) [Can't get that one :(]
protected override void CopyProperties(DataControlField newField)
protected virtual string FormatDataTextValue(object dataTextValue)
public override void ValidateSupportsCallback()
それぞれを確認しましたが、値が設定されていません。これは、OnDataBindField(object、EventArgs)で発生しているようです。
if ((this.textFieldDesc == null) && (component != null))
{
...
this.textFieldDesc = TypeDescriptor.GetProperties(component).Find(dataTextField, true);
...
}
if ((this.textFieldDesc != null) && (component != null))
{
object dataTextValue = this.textFieldDesc.GetValue(component);
str = this.FormatDataTextValue(dataTextValue);
}
...
((IButtonControl) control).Text = str;
これは、値を変更しようとする前に発生すると思いますが、前に述べたように、button.Textはstring.Emptyです。cell_DataBindingメソッドでは空です。
誰かアイデアはありますか?