sandeep kodepaka

sandeep kodepaka

  • NA
  • 106
  • 210.2k

How to Add rows Dynamically to GridView

Jan 4 2011 4:14 AM

Hi team
        Can anyone tell me how we can add rows dynamically in gridview.
DataTable
dt = new DataTable();
try
{
CheckBox chk = new CheckBox();
foreach (GridViewRow row in gvDept.Rows)
{
chk = (
CheckBox)row.FindControl("ChkDept");
if (chk.Checked == true)
{
Label lbl = (Label)row.FindControl("lblcode");
string code = lbl.Text;
dt = BLSht.GetEmployeeListAsPerDept(code);
if (dt.Rows.Count>0)
{
DataRow newRow = dt.NewRow();
gvAppEmployees.DataSource = dt;
}
else
{

}
}
else
{
}
}
gvAppEmployees.DataSource = dt;
gvAppEmployees.DataBind();
}
catch (Exception ex)
{
}
}

Answers (2)