在asp.net中查询结果在datagrid中显示,如果编码为“简体中文”显示为乱码!
我用尽了我想到的方法也没有解决!求高手相助!!

解决方案 »

  1.   

    代码如下: 
    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            '在此处放置初始化页的用户代码
            Dim AdoConn As New SqlClient.SqlConnection("user id=sa;data source=wangyong;persist security info=False;initial catalog=Xygl_XGL")
            Dim AdoAdp As New SqlClient.SqlDataAdapter
            Dim AdoTab As DataSet
            Dim Adocom As SqlClient.SqlCommand
            If (IsPostBack) Then
                Try
                    _region = New Region
                Catch
                    ' unknown region
                    _region = Nothing
                End Try
            Else
                _region = Nothing
            End If
            Adocom = New SqlClient.SqlCommand
            Adocom.Connection = AdoConn
            Adocom.CommandType = CommandType.Text
            Adocom.CommandText = "select lshao  as 流水号,spmc as 商品名称,spdm as 商品代码,je as 金额 from xx"
            AdoAdp.SelectCommand = Adocom
            AdoTab = New DataSet
            AdoTab.Clear()
            AdoAdp.Fill(AdoTab)
            DataGrid1.DataSource = AdoTab.Tables(0)
            DataGrid1.DataBind()
            DataGrid1.Font.Name = "宋体"
            Dim i As Integer
            Dim j As Integer
            For i = 0 To DataGrid1.Items.Count - 1
                For j = 0 To DataGrid1.Columns.Count - 1
                    URLEncoding(DataGrid1.Items(i).Cells(j).Text)
                Next
            Next
            DataGrid1.DataBind()
         End Sub
      

  2.   

    html页面里面加了一句 
    <%@ Page CodeBehind="ind22.aspx.vb" Language="vb" AutoEventWireup="false" Inherits="test.ind22" contentType="text/html; charset=gb2312"%>
    但是不管用
      

  3.   

    Private Function URLEncoding(ByVal vstrIn As String)
            Dim strReturn As String
            strReturn = ""
            Dim i As Integer        Dim ThisChr As String        Dim innerCode, Hight8, Low8 As Integer        For i = 1 To vstrIn.Length            ThisChr = Mid(vstrIn, i, 1)            If Abs(Asc(ThisChr)) < &HFF Then
                    strReturn = strReturn & ThisChr
                Else
                    innerCode = Asc(ThisChr)
                    If innerCode < 0 Then
                        innerCode = innerCode + &H10000
                    End If
                    Hight8 = (innerCode And &HFF00) \ &HFF
                    Low8 = innerCode And &HFF
                    strReturn = strReturn & "%" & Hex(Hight8) & "%" & Hex(Low8)
                End If
            Next
            URLEncoding = strReturn
        End Function
      

  4.   

    把web.config中的配置改一下:
    <!--  全球化        此节设置应用程序的全球化设置。-->
    <globalization 
            requestEncoding="gb2312" 
            responseEncoding="gb2312" 
            fileEncoding="gb2312"
    />
      

  5.   

    看你的webconfig的配置 估计还是utf8
      

  6.   

    你们说得是不是\web\config.web文件??