我正在使用GridView。我在编辑行期间在文本框(t5和t6)中更改值时遇到问题。 我想按下TextBox中的编辑按钮(t5和t6)后只有前10个字符(yyyy-mm-dd)。粘贴下面的代码。
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
Label350.Text = string.Empty;
GridView1.EditIndex = e.NewEditIndex;
GridViewRow row = GridView1.Rows[GridView1.EditIndex];
GridView1.Columns[0].Visible = true;
GridView1.Columns[8].Visible = true;
GridView1.DataSourceID = "";
GridView1.DataSource = Session["TaskTable"];
GridView1.DataBind();
GridView1.Columns[0].Visible = false;
GridView1.Columns[8].Visible = false;
TextBox t5 = row.FindControl("TextBox5") as TextBox;
TextBox t6 = row.FindControl("TextBox6") as TextBox;
if (t5.Text.Length > 11)
{
string v = t5.Text;
v.Substring(0, 10);
t5.Text = v;
}
if (t6.Text.Length > 11)
{
string v2 = t6.Text;
v2.Substring(0, 10);
t6.Text = v2;
}
}
单击编辑按钮时出现错误消息。
“对象引用未设置为对象的实例”
需要帮助!