获取Repeater中Footertemplate内控件的值
我在Repeater控件中的Footertemplate中进行插入操作,但是获取不到Footertemplate中控件的值(即控件Text="")
代码如下:
TextBox Txt_Title = this.Repeater1.Controls[this.Repeater1.Controls.Count - 1].FindControl("txtTitle1") as TextBox;
TextBox Txt_Director = this.Repeater1.Controls[this.Repeater1.Controls.Count - 1].FindControl("txtDirector1") as TextBox;
CheckBox chkInTheaters = this.Repeater1.Controls[this.Repeater1.Controls.Count - 1].FindControl("chkInTheaters1") as CheckBox;
SqlConnection conn = new SqlConnection(str);
conn.Open();
string sql = " insert into Movies( Title,Director,InTheaters) values( @Title,@Director,@InTheaters)";
SqlCommand cmd = new SqlCommand(sql, conn);
SqlParameter[] param = {
new SqlParameter("@Title",Txt_Title.Text),
new SqlParameter("@Director",Txt_Director.Text),
new SqlParameter("@InTheaters",chkInTheaters.Checked),
};
cmd.Parameters.AddRange(param);
int result = cmd.ExecuteNonQuery();
conn.Close();
就执行上面的代码,可以进行插入操作,但是都没有获取到TextBox中Text的相应的值。插入的都是空值(断点调试时Txt_Title.Text="" Txt_Director.Text="" 可是相应的文本框中我输入值了。 )
什么原因啊???
------解决方案--------------------
获取方法是没错。。。
绑定是在IsPostback中吗?