C# 如何取formview里的textbox的值??
前台代码:<asp:FormViewID="FormView1"runat="server"DataKeyNames="CommentId"Visible="false"...
前台代码:<asp:FormView ID="FormView1" runat="server" DataKeyNames="CommentId" Visible="false"
onitemupdating="FormView1_ItemUpdating" >
<EditItemTemplate>
<tr><td>评论者ID:</td>
<td><asp:TextBox ID="TextBox3" runat="server" Text='<%#Eval("ReaderId")%>'></asp:TextBox></td></tr>
</EditItemTemplate>
</asp:FormView>
.cs代码:
protected void FormView1_ItemUpdating(object sender, FormViewUpdateEventArgs e){
SqlParameter[] parments = new SqlParameter[4];
parments[0] = new SqlParameter("@AwardPoints", SqlDbType.Int);
parments[0].Value = 20;
parments[1] = new SqlParameter("@CommentId", SqlDbType.Int);
parments[1].Value = this.FormView1.DataKey.Value;
parments[2] = new SqlParameter("@ReaderId", SqlDbType.Int);
parments[2].Value = TextBox3;
parments[3] = new SqlParameter("@AwardTime", SqlDbType.DateTime);
parments[3].Value = DateTime.Now.ToString();
}
TextBox3的值怎么取? 展开
onitemupdating="FormView1_ItemUpdating" >
<EditItemTemplate>
<tr><td>评论者ID:</td>
<td><asp:TextBox ID="TextBox3" runat="server" Text='<%#Eval("ReaderId")%>'></asp:TextBox></td></tr>
</EditItemTemplate>
</asp:FormView>
.cs代码:
protected void FormView1_ItemUpdating(object sender, FormViewUpdateEventArgs e){
SqlParameter[] parments = new SqlParameter[4];
parments[0] = new SqlParameter("@AwardPoints", SqlDbType.Int);
parments[0].Value = 20;
parments[1] = new SqlParameter("@CommentId", SqlDbType.Int);
parments[1].Value = this.FormView1.DataKey.Value;
parments[2] = new SqlParameter("@ReaderId", SqlDbType.Int);
parments[2].Value = TextBox3;
parments[3] = new SqlParameter("@AwardTime", SqlDbType.DateTime);
parments[3].Value = DateTime.Now.ToString();
}
TextBox3的值怎么取? 展开
展开全部
TextBox txtBox= this.FormView1.FindControl("TextBox的ID") as TextBox;
追问
分是你的了,呆一会给。
如果把textbox改成label呢?
追答
一样的,Label lb=this.FormView1.FindControl("Label的ID") as Label;
因为this.FormView1.FindControl("Label的ID") 这个方法是获取它里面的控件,到底是哪个控件这个只需要转换成相应的控件就行了。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询