日期:2014-05-17 浏览次数:20492 次
protected void AddNew_Click(object sender,EventArgs e)
{
DataTable dt=this.GetDataFromGrid();
DataRow newRow=dt.NewRow();
dt.Rows.Add(newRow);
this.gvRoleInfo.DataSource=dt;
this.gvRoleInfo.DataBind();
}
protected DataTable GetDataFromGrid()
{
DataTable dt1=new DataTable("tb01");
dt1.columns.Add("id");
dt1.columns.Add("name");
for(int i=0;i<gvRoleInfo.Rows.Count;i++)
{
GridViewRow gRow=gvRoleInfo.Rows[i];
DataRow newRow=dt1.NewRow();
newRow[0]=gvRoleInfo.DataKeys[i].Value;
newRow[1]=((TextBox)gRow.FindControl("txtRoleName")).Text; dt1.Rows.Add(newRow);
}
dt1.AcceptChanges();
return dt1;
}