protected void dtg_kalemler_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
DataRowView m = (DataRowView)e.Row.DataItem;
if (m != null)
{
veya
+ ((DataTable)m.DataView.Table) {} System.Data.DataTable
- ((DataRowView)e.Row.DataItem).Row {System.Data.DataRow} System.Data.DataRow
((DataTable)((DataRowView)e.Row.DataItem).DataView.Table)
((DataTable)((DataRowView)e.Row.DataItem).DataView.Table).Rows.Count
((DataRowView)e.Row.DataItem).Row[0]
((DataRowView)e.Row.DataItem).Row[0].GetType()==System.Type.GetType("System.String")
protected void dtg_kayitlar_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header)
{
for (int i = 0; i < e.Row.Cells.Count; i++)
{
e.Row.Cells[i].HorizontalAlign = HorizontalAlign.Center;
}
}
else
if (e.Row.RowType == DataControlRowType.DataRow)
{
for (int i = 0; i < e.Row.Cells.Count; i++)
{
//TableCell cell = e.Row.Cells[i];
if (((DataRowView)e.Row.DataItem).Row[i].GetType() == System.Type.GetType("System.Decimal") || ((DataRowView)e.Row.DataItem).Row[i].GetType() == System.Type.GetType("System.Double"))
{
e.Row.Cells[i].HorizontalAlign = HorizontalAlign.Right;
}
}
}
}
//bu daha iyi oldu
List<Int32> kk = new List<Int32>(); //kackolon
decimal[] kt;//kolontoplam
protected void dtg_kayitlar_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header)
{
//opsiyonel
kk = new List<Int32>();
kt = null;
}
else
if (e.Row.RowType == DataControlRowType.DataRow)
{
if(kt==null)
{
DataTable dt = ((DataTable)((DataRowView)e.Row.DataItem).DataView.Table);
for (int i = 0; i < dt.Columns.Count; i++)
{
if (dt.Columns[i].DataType == System.Type.GetType("System.Decimal") || dt.Columns[i].DataType == System.Type.GetType("System.Double"))
{
kk.Add(i);
}
}
kt = new decimal[kk.Count];
for (int i = 0; i < kk.Count; i++)
{
for (int j = 0; j < dt.Rows.Count; j++)
{
decimal t = 0.0m;
decimal.TryParse(dt.Rows[j][Convert.ToInt16(kk[i])].ToString(), out t);
kt[i] += t;
}
}
}
for (int i = 0; i < e.Row.Cells.Count; i++)
{
if (kk.Contains(i))
{
e.Row.Cells[i].HorizontalAlign = HorizontalAlign.Right;
e.Row.Cells[i].Text = Convert.ToDecimal(((DataRowView)e.Row.DataItem).Row[i]).ToString("N2");
}
}
}
else
if (e.Row.RowType == DataControlRowType.Footer)
{
for (int i = 0; i < kk.Count; i++)
{
for (int j = 0; j < e.Row.Cells.Count; j++)
{
if (kk.Contains(j))
{
e.Row.Cells[j].HorizontalAlign = HorizontalAlign.Right;
e.Row.Cells[j].Text = kt[i].ToString("N2");
e.Row.Cells[j].Font.Bold = true;
}
}
}
}
}