Thursday, April 12, 2007

VS2005 ASP.NET Gridview Date Format

tried to format date boundfield to {0:dd/MM/YYYY}, it won't work, in order to solve the problem, you need to set the "HtmlEncode" of the column to "false"

Wednesday, March 28, 2007

ASP.NET 2005 issues with creating object data adapter in design view

normally when i create a table adapter in design view, i will have this list on the last step
Generated SELECT statement.
Generated INSERT statement.
Generated UPDATE statement.
Generated DELETE statement.
Generated table mappings.
Generated Get method.
Generated Update methods.
How come when i use Authors Table in Pubs sample database to create a table adapter, the line "Generated DELETE statement." is missing? (which means that the delete statement wasnt generated)

It is because:
there was no PK set in the author table when i took it out of the Pub database
now with a defined PK (the AuthorID), all the statements were generated correctly.
The designer just didn't provide enough information explaning why some of the statements havn't been generated. maybe it's something need to be improved....

Friday, March 16, 2007

how to install AJAX Control Toolkit

I went on to the http://www.codeplex.com/AtlasControlToolkit/Release/ProjectReleases.aspx?ReleaseId=1425 downloaded the toolkit, but no idea how to installed.

this is the place where i found the solution, hope it can help you too http://ajax.asp.net/ajaxtoolkit/Walkthrough/Setup.aspx

Thursday, March 15, 2007

ASP.NET AJAX, not let autopostback items cause page reload when the postback occurs

e.g. on my form, clicking on the navigation items (or a dropdownlist control) on the left of screen will filter/refresh the gridview on the right hand side, how can i achieve this using Ajax and not let the navigation items (or a dropdownlist control) to reload themselves? (only the gridview refreshes) the dropdownlist has already been placed outside of UpdatePanel. the whole page reloads because the dropdownlist is "autopostback". I found 3 lines of code that helped me to stop the whole page reload:




This can also be achieved by setting "Triggers" property of the UpdatePanel in design view


Monday, March 12, 2007

any ideas?

i need to write up a research proposal this semester, what are the hot topics related to information systems at the moment? hope someone can help me out~

Thursday, March 01, 2007

I am back!

happy chinese new year! now i am back to work & study, wish myself great achievement in 2007!

Thursday, December 28, 2006

char, varchar, nchar, nvarchar

nchar and nvarchar are used for unicode data, which require twice as much space (bytes) to store the same non-unicode characters. It is a significant disadvantage to use nchar and nvarchar if we do not need unicode charactors. Only use nchar & nvarchar when you need unicode charactors
use char & nchar when the length of the data is fixed, e.g. all customerID must be CUST_XXXX. use varchar and nvarchar when the length of the data is uncertain, e.g. customerID starts from 1 to 100000.

Monday, December 18, 2006

asp.net2.0 upload file

use FileUpload control. this example checks for file type, empty file

protected void btnSaveFile_Click(object sender, EventArgs e)
{
if (IsPostBack)
{
Boolean fileOK = false;
String path = @"C:\temp\";
if (FileUpload1.HasFile)
{
String fileExtension =
System.IO.Path.GetExtension(FileUpload1.FileName).ToLower();
String[] allowedExtensions =
{ ".gif", ".png", ".jpeg", ".jpg" };
for (int i = 0; i < fileextension ="="" fileok =" true;" text = "File uploaded!" text = "File could not be uploaded." text = "Cannot accept files of this type.">

reference: http://msdn2.microsoft.com/en-us/library/ms227669.aspx

Thursday, December 14, 2006

ASP.NET 2.0 “Ambiguous match found” error

when trying to load an ASPX page. The error was a “Parser Error” with “Ambiguous match found”.
The problem could be caused by having a member variable and a control variable with the same name (but different casing)
e.g.
private double aVariable = 0;
AnVariable.Text = aVariable .ToString("c");

The code will compile, and will run locally, but fails when deployed.

The solution is to rename the private member variables

*Thanks to Simon for the finding
*the reference: http://weblogs.asp.net/pjohnson/archive/2006/08/11/Ambiguous-match-found.aspx

Wednesday, December 06, 2006

unit testing issue (access denied - aborted) - VS Team - Developers

Symptom:
when i try to test a method, the result says "Aborted", and the error message was:
"Failed to Queue Test Run "@MACHINE1" 2006-12-04 17:13:30' with id {********-****-****-****-************}: Microsoft.VisualStudio.TestTools.TestManagement.ExecutionException: Test Run deployment issue: The location of the file or directory '\\server1\users\ab\my documents\visual studio 2005\projects\webservicepractice1\testproject1\bin\debug\testproject1.dll' is not trusted."

Solution
1. Control Panel --> .NET Framework 2.0 Configuration --> Runtime Security Policy --> Machine --> All_Code
2. Right click All_Code, select "New...", and give a name for your new group. Click Next and Next again
3. Type in "\\machine_name\shared_folder\assembly.dll" or "\\machine_name\shared_folder\*" and click Next
5. Make sure permission is set to FullTrust. Click Next, and Finish

.NET should be closed all the time while doing these settings

Thursday, November 30, 2006

create & call stored procedure in ASP.NET 2.0 & MSSQL DB

<--CREATE-->
ALTER PROCEDURE dbo.NumOfRecords
AS
SELECT COUNT(*) FROM Branding
RETURN

<--CALL-->
protected void Button8_Click(object sender, EventArgs e)
{
SqlConnection newConn = new SqlConnection("Data Source=localhost;Initial Catalog=TCdatabase;Integrated Security=True;Pooling=False");
SqlCommand newComm = new SqlCommand("NumOfRecords", newConn);

newConn.Open();
int theTotal = (Int32)newComm.ExecuteScalar();
Response.Write(theTotal.ToString());
newConn.Close();
}

messagebox in ASP.NET 2.0

The basic concept is to use JavaScript. Below only shows one way of implementing javascript for messagebox:

switch (txtName.Value)
{
case ("aaa"):
Page.ClientScript.RegisterStartupScript(this.GetType(),"Alert","< script language="javascript" >alert('AAA');< /script >
");
break;

case ("bbb"):
Page.ClientScript.RegisterStartupScript(this.GetType(), "Alert", "< script language="javascript" >alert('BBB');< /script >
");
break;


}

Wednesday, November 22, 2006

deploy applications that use Microsoft SQL Server 2005 Express Edition (SQL Server Express),

http://msdn2.microsoft.com/en-us/library/ms165639.aspx

Monday, November 13, 2006

realize inputBox in C#.net by referencing VB.net component

this will add VB.NET runtime dependency in C# application, you can even add a reference to Microsoft.VisualBasic assembly and call InputBox function implemented there:

string aaa = Microsoft.VisualBasic.Interaction.InputBox("enter a name", "Inputbox Demo", "ROCKY", 100, 100);
MessageBox.Show(aaa);

Another way of doing it without referencing VB.net is to create a form that looks like an inputBox:


using System;

namespace MyNamespace
{
public class InputDialog : System.Windows.Forms.Form
{
private System.Windows.Forms.TextBox txtInput;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Button cmdOK;
private System.Windows.Forms.Button cmdCancel;

public string Value
{
get
{
return txtInput.Text;
}
set
{
txtInput.Text = value;
}
}

public InputDialog()
{
// Required for Windows Form Designer support
InitializeComponent();
}

private void InitializeComponent()
{
this.txtInput = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.cmdOK = new System.Windows.Forms.Button();
this.cmdCancel = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// txtInput
//
this.txtInput.Location = new System.Drawing.Point(48, 16);
this.txtInput.Name = "txtInput";
this.txtInput.Size = new System.Drawing.Size(232, 20);
this.txtInput.TabIndex = 0;
this.txtInput.Text = "";
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(8, 16);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(33, 16);
this.label1.TabIndex = 1;
this.label1.Text = "Input:";
//
// cmdOK
//
this.cmdOK.DialogResult = System.Windows.Forms.DialogResult.OK;
this.cmdOK.Location = new System.Drawing.Point(69, 48);
this.cmdOK.Name = "cmdOK";
this.cmdOK.TabIndex = 2;
this.cmdOK.Text = "OK";
//
// cmdCancel
//
this.cmdCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.cmdCancel.Location = new System.Drawing.Point(149, 48);
this.cmdCancel.Name = "cmdCancel";
this.cmdCancel.TabIndex = 2;
this.cmdCancel.Text = "Cancel";
//
// Form1
//
this.AcceptButton = this.cmdOK;
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.CancelButton = this.cmdCancel;
this.ClientSize = new System.Drawing.Size(292, 86);
this.Controls.Add(this.cmdOK);
this.Controls.Add(this.label1);
this.Controls.Add(this.txtInput);
this.Controls.Add(this.cmdCancel);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
}
}
}

Sunday, November 05, 2006

convert sting value to the value of datetimepicker

generally the format should be everything except the AM part.

DateTime result = DateTime.Now;

if (DateTime.TryParse(this.label1.Text, out result))

{

this.dateTimePicker.Value = result;

}

We can also use DateTime.TryParseExact:
http://msdn2.microsoft.com/en-us/library/h9b85w22(VS.80).aspx