gpt4 book ai didi

c# - 在 OrderedDictionary 上使用 linq 以使用 GridView 获取最大值

转载 作者:行者123 更新时间:2023-11-30 12:15:53 25 4
gpt4 key购买 nike

我有一个自定义的 GridView 控件(继承 system.web.ui.webcontrols.gridview),我想根据用户最近插入的值(inserted values不致力于数据源)。

在 Grid.DataBound 中,我能够查询单个列的单元格以获取我设置为 TextBox 的当前最大值。

int maxTimeSlot = grid.Rows.OfType<GridViewRow>().Max(r => int.Parse(r.Cells[1].Text));

插入新行后,我可以访问 Grid 的“插入”属性,其中包含到目前为止所有插入行的列表,例如:

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)

以上是我对它如何运作的“想法”,但自然不会。

最佳答案

对 Select 的调用将 NewValues.Values 中的每个 KeyValuePair 投影为 bool 值,因此您无法再访问原始数据。

看起来您正在尝试查找所有“时隙”值,我认为您需要类似的东西

NewValues.Values.OfType<KeyValuePair<object, object>>().Where(r => r.Key == "timeslot").Max(t => (int)t.Value)

关于c# - 在 OrderedDictionary 上使用 linq 以使用 GridView 获取最大值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6428280/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com