formview模版内的文本框,绑定了数据源,请问如何设置默认值?还有怎么赋值?

解决方案 »

  1.   

    formView有三种状态!下面是在插入状态时对id为TextBox1进行赋值:
        protected void FormView1_DataBound(object sender, EventArgs e)
        {
            if (FormView1.CurrentMode == FormViewMode.Insert)
            {
                TextBox t1 = FormView1.FindControl("TextBox1") as TextBox;
                t1.Text = "aaa";
            }
        }
      

  2.   

    我用的VB这样
    If FormView1.CurrentMode = FormViewMode.Insert Then
                Dim t1 As TextBox = FormView1.FindControl("aaiTextBox")
                t1.Text = "aaaa"
    End If
    会报错“未将对象引用设置到对象的实例。”
      

  3.   

    应该是没有找到id为aaiTextBox的控件,你可以string str =  FormView1.FindControl("aaiTextBox").class  打断点看看是结果是什么。
      

  4.   

    protected   void   FormView1_DataBound(object   sender,   EventArgs   e) 

            if(FormView1.CurrentMode==FormViewMode.Insert) 
          { 
                    TextBox   txt1=FormView1.FindControl( "TextBox1 ") as TextBox; 
                    txt1.Text=""; 
          } 
    }是否为null
      

  5.   

    以实验DataBound事件无法找到控件,要在load或