如何在插入模式下在formview中将文本设置为textarea

时间:2013-12-18 20:52:54

标签: c# asp.net formview

DemHere是我的textarea控件:

<textarea id="Physical_DemandsTextBox" runat="server" cols="35" rows="6" value='<%# Bind("Physical_Demands") %>' />

这是我的逻辑,适用于其他asp:TextBox控件

if (FormView1.CurrentMode == FormViewMode.Insert)
   {
       TextBox txtPhyDem = FormView1.FindControl("Physical_DemandsTextBox") as TextBox;
   }

   if (txtPhyDem != null)
   {
         txtPhyDem.Text = "Failed Test of the Testing Testers.";
   }         

当我在插入模式下运行应用程序时,文本区域为空白。我该如何解决这个问题?

2 个答案:

答案 0 :(得分:1)

您只需要使用文本框控件替换textarea,如下所示:

    <asp:TextBox ID="Physical_DemandsTextBox" 
        TextMode="MultiLine" Rows="6" Columns="35" 
        runat="server" 
        Text='<%# Bind("Physical_Demands") %>'></asp:TextBox>

答案 1 :(得分:0)

您可以使用Body属性作为示例:

if (FormView1.CurrentMode == FormViewMode.Insert)
{
   Physical_DemandsTextBox.Body = "Failed Test of the Testing Testers.";
}

但你也可以直接使用asp.net控件,对于样本,在webform中更好:

<asp:TextBox id="Physical_DemandsTextBox" runat="server" 
                                          TextMode="Multiline" 
                                          Columns="35" 
                                          Rows="6" />

和代码behine:

if (FormView1.CurrentMode == FormViewMode.Insert)
{
    Physical_DemandsTextBox.Text = "Failed Test of the Testing Testers.";
}