我正在编辑文本框并更改其值。下面是代码片段。
protected void btnedit_Click(object sender, EventArgs e)
{
TextBox txtmonday = new TextBox();
txtmonday.ID = "txtmonday1";
int index = GridView1.EditIndex;
Button btn = (Button)sender;
GridViewRow gvr = (GridViewRow)btn.NamingContainer;
int getindex = gvr.RowIndex;
//string headertext = this.GridView1.Columns[1].HeaderText;
string id = GridView1.Rows[getindex].Cells[4].Text;
DataTable dtfrweekend = new DataTable();
connfordata.Open();
SqlCommand cmdfrgetweekend = new SqlCommand("select s001_Weekending as Weekend from dbo.s001_Timesheets where s001_TimesheetsID ='" +id+ "' ", connfordata);
SqlDataAdapter dafrweekend = new SqlDataAdapter(cmdfrgetweekend);
dafrweekend.Fill(dtfrweekend);
connfordata.Close();
string get = GridView1.HeaderRow.Cells[3].Text.ToString();
BoundField bf = new BoundField();
bf.DataField = "Monday";
txtmonday.Text = GridView1.Rows[getindex].Cells[3].Text;
GridView1.Rows[getindex].Cells[3].Controls.Add(txtmonday);
}
当我点击更新时,我无法在编辑模式下更改值。请建议一个解决方案以获取之前更改的值。谢谢.Below是用于更新的代码段。
protected void btnupdate_Click(object sender, EventArgs e)
{
//string get = txtmonday.Text;
//String sValue = Request.Form["txtmonday"];
// GridView1.DataBind();
TextBox tbfrreplace = new TextBox();
Button btn = (Button)sender;
GridViewRow gvr = (GridViewRow)btn.NamingContainer;
int getindex = gvr.RowIndex;
BoundField bf2 = new BoundField();
bf2.DataField = "Monday";
//tbfrreplace.Text = GridView1.Rows[getindex].Cells[3].Text;
// TextBox tbfrreplace1 = GridView1.FindControl("tbfrreplace") as TextBox;
// GridView1.Rows[getindex].Cells[3].Controls.Add(tbfrreplace);
}