Master\Child for Datagrid
Declare global variable
DataSet ds = new DataSet();
double dTotalSalary=0;
private void dgMaster_SelectedIndexChanged(object sender,
System.EventArgs e)
{
int iDeptId;
iDeptId = Convert.ToInt32(
dgMaster.DataKeys[dgMaster.SelectedIndex]);
DataView dv = new DataView(fetchChildData());
dv.RowFilter = "DeptId = " + iDeptId;
BindChild(dv);
}
private void dgChild_ItemDataBound(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if(e.Item.ItemType == ListItemType.Item
e.Item.ItemType == ListItemType.AlternatingItem)
{
dTotalSalary +=
Convert.ToDouble(e.Item.Cells[2].Text);
}
else if(e.Item.ItemType == ListItemType.Footer)
{
e.Item.Cells[0].ColumnSpan =3;
e.Item.Cells[0].HorizontalAlign =
HorizontalAlign.Center;
e.Item.Cells.RemoveAt(2);
e.Item.Cells.RemoveAt(1);
e.Item.Cells[0].Text = "Total Salary: " +
dTotalSalary.ToString("C");
}
}
No comments:
Post a Comment