5

I have this DataTable that has a varying set of columns except for a sequence number.

| Sequence | Value | Tax | Duty | Total |

Any number of columns should be accepted with unique column names.

To display that table, I need to use an ObjectDataSource mapped to a presenter class with a Select method.

class Presenter {
    [DataObjectMethod(DataObjectMethodType.Select)]
    public DataView GetDutyAndTax() { ... }
}

The ObjectDataSource is then bound to a GridView with AutoGenerateColumns set to true. Sequence is the data key.

So far, that works for selecting the table. The problem comes when I need to update the table. The ObjectDataSource keeps nagging me to have an update method with the exact same parameters with that of the columns in the table.

public void EditDutyAndTax(string Value, string Tax, string Duty, string original_Sequence) { ... }

But I can not create a method like that because I don't know the set of columns needed.

I tried using a method with variable parameter list but it doesn't want to use it.

public void EditDutyAndTax(params object[] values) { ... }

On idea I have now is to create a set of update methods like this in Presenter:

public void EditDutyAndTax(string value1, string original_Sequence) { ... }
public void EditDutyAndTax(string value1, string value2, string original_Sequence) { ... }
public void EditDutyAndTax(string value1, string value2, string value3, string original_Sequence) { ... }
//an so on...

But I neither think that's gonna get through code review nor like the idea.

The other idea I have is to create a dynamic method and attach that (if possible) to the Presenter class or wherever at runtime, but I'm not really sure if that would work.

So if you guys have any solution, please help. Thanks so much!

Carlos

4

1 回答 1

3

在我看来,您将不得不放弃使用 ObjectDataSource 声明性模型,并转到数据源的“老派”设置并在回发中手动绑定网格(或加载,视情况而定),然后手动处理编辑/更新。

DataSource 对象对您如何使用它们非常讲究——如果您尝试越界,它就不能很好地工作,如果有的话。

于 2008-09-29T13:45:36.710 回答