我将ObjectDataSource的DataObjectTypeName属性设为一个实体类,通过GridView可以进行更新和删除,这时,实体类被自动实例化了,并自动传给Update等方法做为参数,但我要将文本框的值而非GridView行中的值作为Insert的参数时,就不知道怎么办了,GridView都是自动的啊。请各位大侠帮忙。

解决方案 »

  1.   

    不是GridView中的文本框,是页面上另外添加的
      

  2.   

    在GridView外,是没办法执行GridView内的Update方法的,
    建议解决办法:
    在页面上加一个FormView来做更新也可以。
      

  3.   

    try to handle objectdatasource's inserting event
    protected void ObjectDataSource1_Inserting(object sender, ObjectDataSourceMethodEventArgs e)
        {
    ....
                e.InputParameters["Score"] = Convert.ToInt32(YourTextBox.Text);
            e.InputParameters["LastModifiedDate"] = DateTime.Now;
        }
      

  4.   

    如果你的输入全部来自你的输入框的话,那么你应该直接调用你的业务组件的对应Insert方法
      

  5.   

    思归老大,照你的提示去做,出现如下错误:ObjectDataSource1.Insert();提示运行这句时没有可插入的值!请问这是为什么?
       protected void LbtUpdate_Click(object sender, EventArgs e)
        {
            ObjectDataSource1.Insert();提示运行这句时没有可插入的值!
            GridView1.ShowFooter = false;
        }
        protected void ObjectDataSource1_Inserting(object sender, ObjectDataSourceMethodEventArgs e)
        {
            TextBox FuncName = (TextBox)GridView1.FooterRow.FindControl("TextBox2");
            TextBox Description = (TextBox)GridView1.FooterRow.FindControl("TextBox2");
            e.InputParameters.Add("FuncName",FuncName.Text);
            e.InputParameters.Add("Description",Description.Text);
        }
      

  6.   

    why are you doing e.InputParameters.Add? don't call ObjectDataSource1.Insert() yourself
      

  7.   

    开始我是按老大的方法试的,是这样的:
            e.InputParameters["FuncName"] = FuncName.Text;
            e.InputParameters["Description"] = Description.Text;
    因为提示没有可插入的值,所以试了一下e.InputParameters.Add,也不行,复制代码时,就只复制了后一次的。请老大再发一下话。
      

  8.   

    don't you what you are doing, consider to use a DetailsView or FormView to insert records, or call your business object's Insert-related method directly