Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Gridview encoding, or how to run commands before gridview's default databinding, or, how do I disable default databinding at all?

Reply
Thread Tools

Gridview encoding, or how to run commands before gridview's default databinding, or, how do I disable default databinding at all?

 
 
Sergei Shelukhin
Guest
Posts: n/a
 
      11-12-2006
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.ConnectionStri ngs["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?

 
Reply With Quote
 
 
 
 
Mark Rae
Guest
Posts: n/a
 
      11-12-2006
"Sergei Shelukhin" <> wrote in message
news: oups.com...

> I use MySQL database
> public static OdbcConnection GetConnection()


As a matter of interest, why on earth are you using ODBC to connect to
MySQL???

http://dev.mysql.com/downloads/connector/net/1.0.html
http://crlab.com/mysqlnet/


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Databinding expressions are only supported on objects that have a DataBinding event jobs ASP .Net 0 09-25-2007 11:54 PM
Need Help Differentiating Bad Commands From Incomplete Commands Tim Stanka Python 1 08-02-2004 02:08 AM
DataGrid Custom Column Error when DataBinding "does not contain a definition for 'DataBinding'" Earl Teigrob ASP .Net Datagrid Control 1 03-01-2004 04:52 AM
Re: man pages for C commands (GCC commands) Ben Pfaff C Programming 4 06-28-2003 06:21 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57