Gridview encoding, or how to run commands before gridview's default databinding, or, how do I disabl

Discussion in 'ASP .Net' started by Sergei Shelukhin, Nov 12, 2006.

  1. I have the following problem with gridview. I use MySQL database that
    has Russian characters in cp1251 encoding, and I get ????????s instead
    of Russian characters on all my ASP.NET pages.
    To fix this, I use helper function to get database connection, it goes:

    public static OdbcConnection GetConnection()
    {
    OdbcConnection cn = new
    OdbcConnection(ConfigurationManager.ConnectionStrings["DB"].ConnectionString);
    OdbcCommand cmd = new OdbcCommand("set
    character_set_client='cp1251'",cn);
    cn.Open();
    cmd.ExecuteNonQuery();
    cmd.CommandText = "set character_set_results='cp1251'";
    cmd.ExecuteNonQuery();
    cmd.CommandText = "set collation_connection='cp1251_general_ci'";
    cmd.ExecuteNonQuery();
    return cn;
    }
    It works well for all my pages, components etc.

    Gridview, however, uses its own means to get the connection so it still
    gets ????s; to fix it, I use the following:
    protected override void OnPreRender(EventArgs e)
    {
    if (!IsPostBack)
    {
    OdbcConnection cn = SEHelper.GetConnection();
    cn.Close();
    GridView1.DataBind();
    }
    base.OnPreRender(e);
    }

    For some reason (connection pooling? some session kept between mysql
    and aspnet? odbc driver quirks?) everything works perfectly well with
    this code but it's kinda ugly, so, I have the following questions:
    1) Is there any way to change connection used to get data into
    SqlDataSource before it binds to data?
    2) If there's none, is there any way to run commands against the
    connection it uses before it binds?
    3) If that's not possible too, is there any way to disable default
    databinding of GridView/SqlDataSource combo to save extra trip to the
    datatbase, given that I always have to rebind the gridview anyway?
     
    Sergei Shelukhin, Nov 12, 2006
    #1
    1. Advertising

  2. Sergei Shelukhin

    Mark Rae Guest

    Mark Rae, Nov 12, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Hardy Wang

    Encoding.Default and Encoding.UTF8

    Hardy Wang, Jun 8, 2004, in forum: ASP .Net
    Replies:
    5
    Views:
    18,873
    Jon Skeet [C# MVP]
    Jun 9, 2004
  2. =?Utf-8?B?RGFuIFNpa29yc2t5?=

    HOWTO: Use multiline asp:texbox scrollbars on panel that is disabl

    =?Utf-8?B?RGFuIFNpa29yc2t5?=, Apr 11, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    483
    =?Utf-8?B?RGFuIFNpa29yc2t5?=
    Apr 11, 2006
  3. Ben Pfaff

    Re: man pages for C commands (GCC commands)

    Ben Pfaff, Jun 24, 2003, in forum: C Programming
    Replies:
    4
    Views:
    3,977
    Thomas Stegen
    Jun 28, 2003
  4. Tim Stanka
    Replies:
    1
    Views:
    806
    Jeff Epler
    Aug 2, 2004
  5. cs_professional
    Replies:
    14
    Views:
    5,271
    cs_professional
    Dec 12, 2010
Loading...

Share This Page