【问题标题】:Change one DataObject field's value before insert using ObjectDataSouce在使用 ObjectDataSource 插入之前更改一个数据对象字段值
【发布时间】:2013-05-01 11:49:01
【问题描述】:

我将 RadGrid 与 ObjectDataSource 绑定,并且 ObjectDataSource 正在使用我的存储库进行 CRUD 操作,问题是:

  1. 我想在插入日期之前更改它们的格式。
  2. 我想设置一个字段值“我会从 QueryString 中获取”

我尝试了 ItemCreating 和 ItemCreated 事件,但这不起作用。任何人都有解决方案?

【问题讨论】:

    标签: asp.net webforms radgrid


    【解决方案1】:

    我想通了,你可以使用 Inserting ObjectDataSource Event 来获取将要插入的对象,如下所示:

    protected void obsShiftPeriods_Inserting(object sender, ObjectDataSourceMethodEventArgs e)
    {
        var newShitPeriod = e.InputParameters[0] as DataModel.ShiftPeriod;
        if (newShitPeriod != null) 
         newShitPeriod.ShiftId = Int32.Parse(Request.QueryString["ShiftId"]);
    }
    

    e.InputParameters[0] 是要插入的对象,拿到对象后你可以分配任何字段,然后你完成了 ObjectDataSource 会为你做剩下的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多