Hi
can anybody resolve my query, how to add rows dynamically to gridview.
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Raju KatarePosted Jan 6, 2011, 12:26 AM
try
{
DataTable dt2 = new DataTable();
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)
{
foreach(DataRow drr in dt.Rows)
{
DataRow dr = dt2.NewRow();
dr["EmpCode"] = drr["EmpCode"];
dr["Name"] = drr["Name"];
//if you want to add more columns to dr you can add.
dt2.Rows.Add(dr);
// DataRow newRow = dt.NewRow();
//gvAppEmployees.DataSource = dt;
}
}
else
{
}
}
else
{
}
}
gvAppEmployees.DataSource = dt2;
gvAppEmployees.DataBind();
}
catch (Exception ex)
{
}
}
sandeep kodepakaPosted Jan 5, 2011, 11:48 PM
Raju KatarePosted Jan 5, 2011, 7:44 AM
Send me, I will fix it.
sandeep kodepakaPosted Jan 5, 2011, 7:33 AM
iam sending my source , please help me out
Raju KatarePosted Jan 5, 2011, 6:25 AM
Find solution to your problem in an attachment...
sandeep kodepakaPosted Jan 5, 2011, 1:23 AM
Manikavelu VelayuthamPosted Jan 5, 2011, 1:05 AM
http://www.codeguru.com/forum/showthread.php?t=385892