大家帮忙看看,ViewState为什么不起作用?
我在这里给ViewState赋值:
protected void gviewJd_record_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
{
ViewState[ "Code_id "] = gviewJd_record.Rows[gviewJd_record.SelectedIndex].Cells[2].Text;
//判断目前是否处于编辑模式(EditIndex为1),则禁止选择换行
if (gviewJd_record.EditIndex != -1)
{
gviewJd_record.SelectedIndex = -1;
e.Cancel = true;
Literal txtMsg = new Literal();
txtMsg.Text = " <script> alert( '编辑模式下禁止选择换行! ') </script> ";
Page.Controls.Add(txtMsg);
}
}
在这里取值:
protected void gviewJd_record_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "New ")
{
string recordJd_name = ((DropDownList)gviewJd_record.FooterRow.FindControl( "NewJd_name ")).SelectedValue;
if (recordJd_name.Trim() == " ")
{
ErrorMsg.Text = "请输入检查类型! ";
return;
}
string recordCheck_date = ((TextBox)gviewJd_record.FooterRow.FindControl( "NewCheck_date ")).Text;
if (recordCheck_date.Trim() == " ")
{
ErrorMsg.Text = "请输入检查日期! ";