gpt4 book ai didi

.net - ASP.NET - 在 GridViewRowEventArgs Row.Cells.Item 中使用列名而不是索引

转载 作者:行者123 更新时间:2023-12-04 18:51:24 24 4
gpt4 key购买 nike

我想对 GridView 中的单元格执行一些简单的自动格式化。到目前为止,我有以下代码:

Private Sub gridviewRefreshPanel_RowDataBound( _
ByVal sender As Object, _
ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) _
Handles gridviewRefreshPanel.RowDataBound

Dim readyStatus As String = DataBinder.Eval(e.Row.DataItem, "READY")

Select Case readyStatus
Case "NO"
e.Row.Cells.Item(5).ForeColor = Drawing.Color.Red
e.Row.Cells.Item(5).Font.Bold = True
Case "N/A"
e.Row.Cells.Item(5).ForeColor = Drawing.Color.Goldenrod
e.Row.Cells.Item(5).Font.Bold = True
Case "YES"
e.Row.Cells.Item(5).ForeColor = Drawing.Color.DarkGreen
e.Row.Cells.Item(5).Font.Bold = True
End Select

End Sub

我想通过列名而不是索引来引用单元格。例如,数据行:
row.Item("ON_TIME")

如何使用 GridView 实现这一点?

最佳答案

你可以这样做..但这是c#代码

DataRow dr = ((DataRowView)e.Row.DataItem).Row;
dr["ColumnName"]

编辑:把这个条件放在最上面
if (e.Row.RowType == DataControlRowType.DataRow)

关于.net - ASP.NET - 在 GridViewRowEventArgs Row.Cells.Item 中使用列名而不是索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5719481/

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