在 OrderedDictionary 上使用 linq 通过 GridView 获取最大值
我有一个自定义 GridView 控件(继承 system.web.ui.webcontrols.gridview),我想根据用户最近插入的值控制 TextBox 的值(插入的值未提交)到数据源)。
在 Grid.DataBound 中,我可以查询单列的单元格以获取我设置为 TextBox 的当前最大值。
int maxTimeSlot = grid.Rows.OfType<GridViewRow>().Max(r => int.Parse(r.Cells[1].Text));
插入新行后,我可以访问网格的“插入”属性,其中包含迄今为止所有插入行的列表,例如:
GridView.Inserts[0].NewValues & GridView.Inserts[0].OldValues
我需要做的是使用此“插入”列表来获取最大值再次值,但我正在努力查询 NewValues.Values (OrderedDictionaryKeyValueCollection) 来获取该值。
NewValues.Values.OfType<KeyValuePair<object, object>>().Select(r => r.Key == "timeslot").Max(t => (int)t.Value)
以上是我对其如何运作的“想法”,但自然地,事实并非如此。
I have a custom GridView control (inherits system.web.ui.webcontrols.gridview) and I would like to control the value of a TextBox based on values recently inserted by the user (inserted values are not committed to the datasource).
In Grid.DataBound I'm able to query the cells of a single column to get the current max which i set to a TextBox.
int maxTimeSlot = grid.Rows.OfType<GridViewRow>().Max(r => int.Parse(r.Cells[1].Text));
Aftering inserting a new row, I have access to an 'Inserts' property of the Grid which contains a list of all the inserted rows so far, for example:
GridView.Inserts[0].NewValues & GridView.Inserts[0].OldValues
What I need to do is to use this 'Inserts' list to get the max value again, but I'm struggling querying NewValues.Values (OrderedDictionaryKeyValueCollection) to get the value.
NewValues.Values.OfType<KeyValuePair<object, object>>().Select(r => r.Key == "timeslot").Max(t => (int)t.Value)
The above is my 'idea' of how it would work, but naturally, it doesn't.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对 Select 的调用会将
NewValues.Values
中的每个KeyValuePair
投影为布尔值,因此您无法再访问原始数据。因为看起来您正在尝试找到所有“时隙”值,所以我认为您需要类似的东西
The call to Select is projecting each
KeyValuePair
inNewValues.Values
to a boolean, so you no longer have access to the original data.As it looks like you are trying to find all the "timeslot" values, I think you need something like