更新时间:2023-12-01 18:17:22
尝试以下代码
Try the following code
protected void Button2_Click(object sender, EventArgs e)
{
if(Session["dt1"] != null)
{
dt1 = (DataTable)Session["dt1"];
}
DataRow dr1 = dt1.NewRow();
dr1[0] = TextBox2.Text;
dr1[1] = TextBox4.Text;
dr1[2] =TextBox3.Text;
dr1[3] =TextBox5.Text;
dt1.Rows.Add(dr1);
GridView1.DataSource = dt1;
GridView1.DataBind();
Session["dt1"] = dt1;
}
您好,请尝试以下代码
hi try the following code
Button_Click()
{
DataTable dt = new DataTable();
DataRow dr;
dt.Columns.Add("Name");
dt.Columns.Add("Address");
dt.Columns.Add("Number");
//First fill all the date present in the grid
for (int intCnt = 0; intCnt < grd.Rows.Count; intCnt ++)
{
if (grd.Rows[intCnt].RowType == DataControlRowType.DataRow)
{
dr = dt.NewRow();
dr["Name"] = grd.Rows[intCnt].Cells[0].Value;
dr["Address"] = grd.Rows[intCnt].Cells[1].Value;
dr["Number"] = grd.Rows[intCnt].Cells[2].Value;
dt.Rows.Add(dr);
}
}
dr = dt.NewRow();
dr["Name"] = txt1.Text;
dr["Address"] = txt2.Text;
dr["Number"] = txt3.Text;
dt.Rows.Add(dr);
grd.DataSource = dt;
grd.DataBind();
}
如果我犯了任何语法错误,请更正,因为我直接在记事本中写了这段代码
Please make corrections if I made any syntactic mistake because I wrote this code directly in the notepad