DataSourceを取得するGridViewがあります。RowDataBoundで、行セルにいくつかの変更を加える必要がありますが、どのような変更が発生するかを判断するための外部情報が必要です。
static void GridRowDataBoundProbables(object sender, GridViewRowEventArgs e)
{
if(e.Row.RowType == DataControlRowType.Header)
{
foreach (TableCell cell in e.Row.Cells)
{
if (!int.TryParse(cell.Text, out postNum)) continue;
cell.CssClass += " postCell";
cell.Add(new Panel { CssClass = (**isHarness** ? PostHarness : PostThoroughbred) + postNum });
cell.Add(new Label { Text = postNum.ToString() });
}
}
}
グリッドを作成してバインドするときに使用できるisHarnessブール値が必要です。また、グリッドは静的なWebMethod呼び出し中に作成されるため、ページ上でグローバルにすることはできません。
isHarnessの値をこの関数に取り込むにはどうすればよいですか?GridViewRowEventArgsから継承する独自のEventArgsを作成できると思いましたが、新しい引数で実際にブール値を取得する方法がまだわかりません...
編集
isHarnessは、データソースが作成されたときに決定されたブール値ですが、データソースの一部ではありません。
以下は、外部呼び出しのモックです。
[WebMethod]
public static AjaxReturnObject GetProbables(string token, string track, string race, string pool)
{
Tote tote = new Tote(...);
GridView grid = new GridView();
grid.RowDataBound += GridRowDataBound;
grid.DataSource = tote.GetDataSource(); //isHarness is available during creation of DataSource
//Here tote.isHarness is available from property
grid.DataBind();
}