how to add multiple rows in gridview after binding with datatable

Posted by Shailesh21235 under ASP.NET on 6/5/2012 | Points: 10 | Views : 12767 | Status : [Member] | Replies : 3
public DataTable CreatePersonalDetail()
{
DataTable dtPersonalDetailTable = new DataTable();

DataColumn dcName = new DataColumn("Name");
dtPersonalDetailTable.Columns.Add(dcName);

DataColumn dcSurname = new DataColumn("SurName");
dtPersonalDetailTable.Columns.Add(dcSurname);

DataColumn dcAge = new DataColumn("Age");
dtPersonalDetailTable.Columns.Add(dcAge);

DataColumn dcEmail = new DataColumn("Email");
dtPersonalDetailTable.Columns.Add(dcEmail);

DataColumn dcPassword = new DataColumn("Password");
dtPersonalDetailTable.Columns.Add(dcPassword);

DataColumn dcGender = new DataColumn("Gender");
dtPersonalDetailTable.Columns.Add(dcGender);

DataColumn dcProfession = new DataColumn("Profession");
dtPersonalDetailTable.Columns.Add(dcProfession);


DataRow drRow = dtPersonalDetailTable.NewRow();
drRow["Name"] = txtName.Text;
drRow["Surname"] = txtSurName.Text;
drRow["Age"] = txtAge.Text;
drRow["Email"] = txtEmail.Text;
drRow["Password"] = txtPassword.Text;
if (rdoMale.Checked)
drRow["Gender"] = rdoMale.Text;
else
drRow["Gender"] = rdoFemale.Text;
if (chkStudent.Checked)
drRow["Profession"] = chkStudent.Text;
else if (chkManager.Checked)
drRow["Profession"] = chkManager.Text;
else if (chkProgrammer.Checked)
drRow["Profession"] = chkManager.Text;
else
drRow["Profession"] = chkQa.Text;
dtPersonalDetailTable.Rows.Add(drRow);


return dtPersonalDetailTable;

}


gdvPersonalDetail.DataSource = CreatePersonalDetail();
gdvPersonalDetail.DataBind();
here in above class colums and rows are defined when the datas are added in rows than the previous added datas are overlapped. how to add new rows with new entry in grid view????
is it possible to run a loop for the rows entry so that new datas are added in new row???




Responses

Posted by: Vuyiswamb on: 6/6/2012 [Member] [MVP] [Administrator] NotApplicable | Points: 25

Up
0
Down
I really dont understand what you want

Thank you for posting at Dotnetfunda
[Administrator]

Shailesh21235, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Oswaldlily on: 6/7/2012 [Member] Starter | Points: 25

Up
0
Down
DataRow drRow = dtPersonalDetailTable.NewRow(); This line gives you new row


try this
DataTable dt = new DataTable();
dt.Columns.Add(new DataColumn("IssueNo", typeof(string)));
dt.Columns.Add(new DataColumn("PartNo", typeof(string)));



join ur code here ..

Shailesh21235, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vforvijay on: 1/24/2013 [Member] Starter | Points: 25

Up
0
Down
Hi..
To add new rows on gridview ..refer the below link
http://www.dotnetcode.in/2013/01/how-to-add-or-insert-new-row-on.html

Shailesh21235, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response