2014年7月13日 星期日

[RESOLVED] ListBox: Change ListItem text to PASCAL


Hello,


Is it possible to change casing of a ListItem's text to Pascal on Databinding or after it is already databound? I am open to suggestions, if there is a better way to handle to this, such as during the time I query the data from SQL. I heard there may be
a way to accomplish this, but I am not the most proficient at T-SQL.


Any help will be appreciated.



this can be done both in sql or c# side


in sql, u can define custom function (run function in this link) and use it for required field while calling select query


http://blog.sqlauthority.com/2007/02/01/sql-server-udf-function-to-convert-text-string-to-title-case-proper-case/


or in c# code, before setting the listbox datasource, loop through all records of datasource items... say dataset and change its value using Pascal casing


//add reference to system.globalization
TextInfo tInfo = new CultureInfo("en-US",false).TextInfo;

for(int i=0;i{
dataset1.Tables[0].Rows[i]["ColumnName"] = tInfo.ToTitleCase(dataset1.Tables[0].Rows[i]["ColumnName"].ToString())
}

ListBox.DataSource = dataset1;

although, sql server method would be more efficient


hope this helps...



The sql function does work great!


I was curious however, if you or any one else has stumbled upon a way to easily recognize acronyms such as states, etc? Also, if there was a way to get it to ignore "or", "and", "of", etc.


沒有留言:

張貼留言