【问题标题】:convert unbound Gridview column values to lowercase at runtime在运行时将未绑定的 Gridview 列值转换为小写
【发布时间】:2012-02-08 07:26:04
【问题描述】:

我有一个未绑定的 Gridview,它由 Linq to Entities 查询填充,并且希望将特定列中的字符串值转换为小写。

在 Gridview 的 RowDataBound 事件中,我尝试了 StrConv(e.Row.Cells(3).Text, VbStrConv.ProperCase) 但这不起作用。

我还在 LiNQ to Entities 查询中尝试了StrConv(emp.Name, VbStrConv.ProperCase),但返回的 Name 值仍然要转换为小写。

Protected Sub GridView3_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView3.RowDataBound
           If e.Row.RowType = DataControlRowType.DataRow Then

        For i As Integer = 0 To e.Row.Cells.Count - 1
            Dim cellDate As Date
            If Date.TryParse(e.Row.Cells(i).Text, cellDate) Then
                e.Row.Cells(i).Text = String.Format("{0:d}", cellDate)
            End If
        Next
    End If
    StrConv(e.Row.Cells(4).Text, VbStrConv.ProperCase)
End Sub

【问题讨论】:

    标签: asp.net vb.net gridview linq-to-entities


    【解决方案1】:

    据我所见,strConv返回一个字符串,应该使用,我认为是这样的:

    e.Row.Cells(4).Text = StrConv(e.Row.Cells(4).Text, VbStrConv.ProperCase)

    【讨论】:

    • 我已经添加了代码。以下代码行未按预期工作,即将 Cell(4) 中的值更改为小写 StrConv(e.Row.Cells(4).Text, VbStrConv.ProperCase)
    【解决方案2】:

    您是否尝试过这样做:

    字符串 strLower = e.Row.Cells[0].Text.ToLower();

    然后使用strLower作为小写字符串。

    【讨论】:

    • 也试过了,但没有成功
    猜你喜欢
    • 2015-09-02
    • 2021-10-13
    • 1970-01-01
    • 2018-04-21
    • 1970-01-01
    • 2020-10-23
    • 2012-10-19
    • 2020-03-29
    • 2022-01-03
    相关资源
    最近更新 更多