C#を使用してasp.netのボタンクリックに表示するためにグリッドビューを使用しています。
DataSet dsnew = new businessLogic.Biz().getData();
if (dsnew != null && dsnew.Tables[0].Rows.Count > 0)
{
DataView myDataView = new DataView();
myDataView = dsnew.Tables[0].DefaultView;
grdDetail.DataSource = myDataView;
grdDetail.DataBind();
}
そして、rowDataBound では、条件に応じて、dataitem コンテナの値を変更したいと考えています。私は次のようにしていますが、問題は、すべての行にデータセットの最後の行の支払い方法があることです。
<asp:TemplateField ItemStyle-Width="70" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:Label ID="lblPaymentMethod" runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"SellingPaymentMethod") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
protected void grdDetail_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
return;
}
foreach (DataRow dtrCurrentRow in (((System.Data.DataView)grdDetail.DataSource)).Table.Rows)
{
//DataRow row = (DataRow)e.Row.DataItem;
Label lblPaymentMethod = e.Row.FindControl("lblPaymentMethod") as Label;
if (Condition1))
{
lblPaymentMethod.Text = dtrCurrentRow["SellingPaymentMethod"].ToString();
}
else if (Condition 2)
{
lblPaymentMethod.Text = dtrCurrentRow["DeliveryPaymentmethod"].ToString();
}
}