asp.net 2.0 formview模式转换中的问题
public partial class VoteItemList : System.Web.UI.Page
{
private SqlConnection myConnection;
private SqlCommand myCommand;
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
//设置当前投题主题名称
myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["Personal"].ConnectionString);
myCommand = new SqlCommand();
myCommand.Connection = myConnection;
myCommand.CommandType = CommandType.Text;
myCommand.CommandText = "SELECT [VoteTopicName] FROM [VoteTopic] WHERE ([VoteTopicID] = @VoteTopicID)";
myCommand.Parameters.AddWithValue("@VoteTopicID", Request.QueryString.Get("VoteTopicID"));
myConnection.Open();
string result = (string)myCommand.ExecuteScalar();
TopicLabel.Text = result;
myConnection.Close();
}
}
protected void FormView1_ItemInserted(object sender, FormViewInsertedEventArgs e)
{
//增加以后
FormView1.Visible = false;
}
protected void InsertCancelButton_Click(object sender, EventArgs e)
{
//取消插入记录
FormView1.Visible = false;
}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
//进入编辑模式
FormView1.Visible = false;
FormView1.PageIndex = GridView1.SelectedIndex;
FormView1.ChangeMode(FormViewMode.Edit);
FormView1.Visible = true;
}
protected void InsertLinkButton_Click(object sender, EventArgs e)
{
//增加操作,在编辑模式下点这个按钮,必须点两次设置值才起做用。
FormView1.Visible = true;
FormView1.ChangeMode(FormViewMode.Insert);
FormView1.PageIndex = 0;
TextBox temp_TextBox = (TextBox)FormView1.FindControl("VoteTopicIDTextBox");
temp_TextBox.Text = Request.QueryString.Get("VoteTopicID");
temp_TextBox = (TextBox)FormView1.FindControl("VoteItemCountTextBox");
temp_TextBox.Text = "0";
}
}
问题:
进入编辑模式后,点插入按钮,必须点两次设置值才有做用,第一次点击没有设置上值,经测试代码段已经执行。请达人指教。