问题的GridView,绑定()和DropDownList的 [英] Problem with GridView, Bind() and DropDownList

查看:215
本文介绍了问题的GridView,绑定()和DropDownList的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我更新现有的ASP.NET网站。这个网站有一个扩展GridView控件添加一些功能的自定义网格控件类。在该网站的许多页面使用内置的内置于底座的GridView声明双向绑定功能,即柱模板使得调用bind(),这样可以显示并自动更新的数据。这在大多数情况下的罚款。但是,绑定时DropDownList控件现在有一个问题。

I am updating an existing ASP .NET site. This site has a custom grid control class that extends the GridView control to add a few features. Many pages in the site use the built in declarative two-way binding feature that is built into the base GridView, i.e. column templates make calls to Bind() so that data can be shown and updated automatically. This works fine in most cases. However, when binding DropDownList controls there is now a problem.

最近我不得不添加一个功能,允许在某些表中的记录被标记为关闭,即它们可以不再被新的记录被引用插入其他表。​​

Recently I had to add a feature that allows records in some tables to be marked as 'Closed', i.e. they can no longer be referenced by new records being inserted into other tables.

当编辑具有的子记录可以关闭一个DropDownList数据网格行,SelectedValue属性可能被绑定到不列表中存在的ID。这将导致一个ArgumentOutOfRange引发异常。我只是想将DropDownList默认为不选择,如果该记录是封闭的,因此不在列表中。

When editing a data grid row that has a DropDownList of child records that can be closed, the SelectedValue property might be bound to an ID that does not exist in the list. This causes an ArgumentOutOfRange exception to be thrown. I just want the DropDownList to default to no selection if the record is closed and therefore not in the list.

我在寻找解决这个最简单的方法。如果可能的话我不想不得不做出了很大的改动现有code。

I'm looking for the easiest way to solve this. If possible I don't want to have to make a lot of changes to existing code.

我可以通过编程设定在RowDataBound事件DropDownList中的选定索引。但我无法找到更新,同时保留原有的更新功能价值的一种方式。

I can programmatically set the selected index of the DropDownList in the RowDataBound event. But I can't find a way of updating the value whilst keeping the existing update functionality.

实际问题:

有一些方法来扩展DropDownList中,使其忽略无效的值SelectedValue属性?到目前为止,我所看到的唯一的例子不工作。我认为DropDownList的情况下缓存值,它尚未有它的DataSource属性集,因此重写SelectedValue属性是不够的。

Is there some way to extend the DropDownList to make it ignore invalid values for the SelectedValue property? The only example I have seen so far does not work. I think that the DropDownList caches the value in case it has not yet had its DataSource property set, so overriding the SelectedValue property is not sufficient.

可替换地,如果有使用OnRowUpdating事件手动将数据添加到更新的方式那么这将是确定。我曾尝试添加值的GridViewUpdateEventArgs类NewValues​​字典,但它似乎并没有工作。请注意,网格绑定到对象列表,而不是DataSourceControl派生的控件。

Alternatively, if there is a way to use the OnRowUpdating event to manually add the data to the update then that would be OK. I have tried adding values to the NewValues dictionary on the GridViewUpdateEventArgs class but it doesn't seem to work. Note that the grids are bound to lists of objects, not DataSourceControl derived controls.

任何帮助将是AP preciated。谢谢你。

Any help would be appreciated. Thanks.

推荐答案

如果任何人的兴趣,我想我通过重写PerformDataBinding方法和捕捉ArgumentOutOfRangeException出现解决了这个。我怀疑SelectedValue属性可能需要重写,以及如果在两个属性绑定的顺序可能会有所不同。

If anyone's interested, I think I solved this by overriding the PerformDataBinding method and catching the ArgumentOutOfRangeException there. I suspect that the SelectedValue property might need to be overridden as well if the order in which the two properties are bound can vary.

这篇关于问题的GridView,绑定()和DropDownList的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆