SilverlightBinding.com
March 23, 2010
I moved to SilverlightBinding.com for a while for building an asp.net application to hold Silverlight information. If you are interested at Silverlight technology, that would be a good place to go.
select multiple dates in CalendarExtender of AJAX Control Toolkit
October 15, 2009
CalendarExtender of AJAX Control Toolkit (for now, ver 30390) has not a default feature to pick up multiple dates. Vince Xu of MSFT gave an answer in asp.net forum. It helps me much. But, there are some issues in his sample code.
- if clean up the TextBox1 and then add a new date, the old text of TextBox1 will show up again in the textBox1, because the HiddenField1 is not cleaned up at all.
- The “Done” button seems not reasonal. But, without the “done” button, the opened calendar could not be hidden forever.
I fixed them by making a little change. Here is the code sample:
<ajaxToolkit:ToolkitScriptManager runat=”Server” EnablePartialRendering=”true” ID=”ScriptManager1″ />
<asp:TextBox ID=”TextBox1″ runat=”server” ></asp:TextBox>
<ajaxToolkit:CalendarExtender ID=”calendar1″ runat=”Server” BehaviorID=”Calendar1″
TargetControlID=”TextBox1″
OnClientDateSelectionChanged=”dateselect” OnClientHidden=”calendarhidden” OnClientShown=”setInitialValue” />
<script type=”text/javascript”>
var tmpDates = “”;
function setInitialValue() {
tmpDates = $get(‘<%=TextBox1.ClientID %>’).value;
}
function dateselect(ev) {
var calendarBehavior1 = $find(“Calendar1″);
var date = calendarBehavior1._selectedDate.format(“M/dd/yyyy”);
if (tmpDates.indexOf(date) < 0) {
if (tmpDates != “”) { $get(‘<%=TextBox1.ClientID %>’).value = tmpDates + “,” + date; }
else { $get(‘<%=TextBox1.ClientID %>’).value = date; }
}
else { $get(‘<%=TextBox1.ClientID %>’).value = tmpDates; }
}
function calendarhidden(obj) {
var tbxValue = $get(‘<%=TextBox1.ClientID %>’).value;
calendarBehavior = $find(“Calendar1″);
if (tmpDates.toString() != tbxValue.toString()) {
calendarBehavior.show();
}
}
</script>
replace values in the QueryString key/value pairs
October 14, 2009
The URL with a QueryString is something like “apage.aspx?month=10&year=2006&…”, anything in Request.QueryString cannot be changed because it is readonly, but the values of “month” and “year” can be changed as followed:
NameValueCollection nvc = HttpUtility.ParseQueryString(Request.QueryString.ToString());
nvc.Set(“month”, “12″);
nvc.Set(“year”, “2009″);
string newUrl = this.Request.ServerVariables["URL"].ToString() + “?” + nvc.ToString() ;
populate TreeView with DataTable
October 5, 2009
TreeView can be bound with XmlDataSource and SiteMapDataSource controls (vs2008exp). But the data come up from the database, a strongly typed DataSet. So, manually populate a TreeView from a DataTable object, instead of auto binding:
int currYear = 0;
TreeNode curRootNode = new TreeNode();
int i = 0;
do
{
rw = dt.Rows[i];
if (rw.theYear != currYear)
{
currYear = rw.theYear;
TreeNode root = new TreeNode(currYear);
curRootNode = root;
this.TreeView1.Nodes.Add(root);
TreeNode child = new TreeNode(Enum.GetName(typeof(ShortMonthName),rw.theMonth) + “. [" + rw.itemNumber + "]“);
curRootNode.ChildNodes.Add(child);
}
else
{
TreeNode child = new TreeNode(Enum.GetName(typeof(ShortMonthName), rw.theMonth) + “. [" + rw.itemNumber + "]“);
curRootNode.ChildNodes.Add(child);
}
i++;
} while (i < dt.Rows.Count);
Here is the result:

create a TableAdapter method with parameters when using OLEDB
October 2, 2009
If use the following query script for creating a TableAdapter method, like “GetDataById”, when using OLEDB:
“SELECT * FROM aTable WHERE theID=@id”
an error will happen:
“error in where clause near ‘@’ unable to parse query text”
The solution is to use “?”, instead of “@variablename”, so teh following will succeed:
“SELECT * FROM aTable WHERE theID=?”
browser-compatible font families
September 13, 2009
There are five generic font families, each including some fonts:
serif: have finishing strokes, flared or tapering ends, or have actual serifed endings (including slab serifs); are typically proportionately-spaced; often display a greater variation between thick and thin strokes than fonts from the ‘sans-serif’ generic font family. Examples of fonts that fit this description include:
- Garamond
- Georgia
- New York
- Times
- Times New Roman
| font | installed(%) | ||
| win | mac | unix | |
| Georgia | 97.76 | 94.20 | 57.70 |
| Times New Roman | 97.51 | 91.71 | 60.98 |
| Lucida Bright | 30.01 | 59.77 | 73.97 |
sans serif: have stroke endings that are plain — without any flaring, cross stroke, or other ornamentation; are typically proportionately-spaced; often have little variation between thick and thin strokes, compared to fonts from the ‘serif’ family. Examples of fonts that fit this description include:
- Arial
- Geneva
- Helvetica
- Lucida Sans
- Trebuchet
- Verdana
| font | installed(%) | ||
| win | mac | unix | |
| Verdana | 99.13 | 95.58 | 59.67 |
| Tahoma | 98.98 | 74.86 | —- |
| Arial | 98.73 | 96.41 | 65.90 |
| Lucida Sans | 41.17 | 59.77 | 73.97 |
monospace: have the same fixed width so it is similar to a manual typewriter. Examples of fonts that fit this description include:
- Courier New
- Courier
- monospac
| font | installed(%) | ||
| win | mac | unix | |
| Courier New | 98.73 | 90.88 | 64.59 |
| Monaco | 2.77 | 98.34 | 4.11 |
cursive and fantasy are not suggested to be used in the body text.
Some common rules:
- Sans serif for online, serif for print.
- Monospace for typewriter and code.
- Cursive and fantasy for accents.
The following combinations are fairly safe when it comes to universal application across operating systems and browser platforms:
- Arial, Helvetica, sans-serif
- Verdana, Arial, Helvetica, sans-serif
- Georgia, Times New Roman, Times, serif
- Times New Roman, Times, serif
- Courier New, Courier, monospace
[references]
http://www.codestyle.org
http://webdesign.about.com/od/fonts/a/aa080204.htm
http://www.w3.org/TR/CSS2/fonts.html#generic-font-families
“Prof ASP.NET 2.0 Design _ CSS, Themes, and Master Pages”, Wrox, 2007
add combobox items with different text and value
September 3, 2009
We can do it with DataBinding a combobox with DataSet or DataTable object. And we can also do it with customer objects. There are two ways to do this.
Here is the customer object:
public class cbxItem
{
private string _Text;
private long _Value;
public string Text{get{return _Text;}}
public long Value{get{return _Value;}}
public cbxItem(string theText, long theValue)
{
_Text = theText;
_Value = theValue;
}
}
Way 1: using DataBinding with customer objects as DataSet
……
ArrayList cbxObjects= new ArrayList();
while(theDataReader.Read())
{
cbxObjects.Add (new cbxItem (theDataReader.GetString(1),theDataReader.GetInt32 (0)));
}
this.ComboBox1.DataSource = Authors;
this.ComboBox1.DisplayMember =”Text”;
this.ComboBox1.ValueMember = “Value”;
……
Way 2: directly using ComboBox.items.Add(obj) with customer objects:
……
while(theDataReader.Read())
{
ComboBox1.Items.Add (new cbxItem (theDataReader.GetString(1),theDataReader.GetInt32 (0)));
}
……
combine multiple rows in one
September 3, 2009
I have a table as:
itemID tagID
100 111
200 222
200 223
300 333
300 334
300 335
I want to have a select statement to group records by itemID and one itemID will have only one row, multiple tagIDs will be combined in one field.
Step1: create a scalar-valued function (UDF)
ALTER FUNCTION sUDF_itemTagIds(@aItemId int)
RETURNS varchar(MAX)
AS
BEGIN
DECLARE @tagids varchar(max)
SELECT @tagids = COALESCE(@tagids + ‘,’,”) + convert(varchar(20),tagID)
FROM myTable
WHERE itemID = @aItemId
RETURN @tagids
END
GO
Step2: call the UDF from the SQL script:
SELECT itemID,dbo.sUDF_itemTagIds(itemID) as tagIDs
FROM myTable
GROUP BY itemID
Here is the result:
itemID tagIDs
100 111
200 222,223
300 333,334,335
Intro to User Defined Functions
The ability to create a user-defined function (UDF) is a new feature added to SQL Server 2000.
A user-defined function is a database object that encapsulates one or more Transact-SQL statements for reuse. This definition is similar to the one for stored procedures, but there are many important differences between user-defined functions and stored procedures—the most pronounced being what types of data they can return.
Scalar Functions
A scalar function returns a single value of the data type referenced in the RETURNS clause of the CREATE FUNCTION statement. The returned data can be of any type except text, ntext, image, cursor, or timestamp.
Inline Table-Valued Functions
An inline table-valued function returns a variable of data type table whose value is derived from a single SELECT statement.
Multi-Statement Table-Valued Functions
The multi-statement table-valued function is slightly more complicated than the other two types of functions because it uses multiple statements to build the table that is returned to the calling statement. Unlike the inline table-valued function, a table variable must be explicitly declared and defined.
Returns the first nonnull expression among its arguments.
Syntax
COALESCE ( expression [ ,...n ] )
father day gift from my little daughter
June 25, 2009
The mountain is my father
I say help me
He said what
problem do you need help with,
I say heal me,
He stays with me until I feel better,
I say buy this book,
He said Okey,
I say I’m tired on the mountain,
He said we’ll rest
for a while,
…
I am feeling warm from the bottom of my heart, and also I am feeling higher pressure because I know being a mountain is not that easy. Hehe, sweet heart, let me try that,……
This is best gift I had! I am proud of that she can write a poem now, when she is almost nine year old!
use unique index when do insert through SqlDataSource
June 19, 2009
email is not a primary but can not be duplicated, otherwise, the same query would get different result. I have a DetailsView bound to a SqlDataSource and then call a sproc to insert a new record. The simple solution to keep from creating two records with one same email is to set the email field as a unique index:
Create Unique Index indx_tablename_columnName On tableName (columnName)
When somebody tried to create a dup record, SqlDataSource1_ItemInserted would get an error message. Then, we can capture it and do something else…
The better way is to modify the sproc as:
Create Proc [Sp_Insert]
@email varchar(128),
……
@returnValue int output
As
If Exists(Select * From theTable Where email=@email)
Begin
Set @returnValue = 0
End
Else
Begin
Insert Into theTable (email,…) Values(@email,…)
Set @returnValue = 1
End
So get a flag in SqlDataSource1_ItemInserted, instead of an error message, no error happened in SQlServer.
