http://msdn2.microsoft.com/en-us/library/2cf62fcy(VS.80).aspx
Examples of Nullable Types
Any value type may be used as the basis for a nullable type. For example:
int? i = 10;
double? d1 = 3.14;
bool? flag = null;
char? letter = 'a';
int?[] arr = new int?[10];
2008年3月28日 星期五
2008年3月26日 星期三
如何取得Gridview 隱藏欄位的值
在某些時候,我們會想利用Gridview的欄位來放Postback後要用到的資料,但又不想讓這些欄位顯示出來,這時候你可以在 GridView1_RowCreated 這個event,將這些欄位的visible 設成 false,如此在 Postback 時就可以取得這些欄位的值,範例如下:
if ((e.Row.RowType == DataControlRowType.Header e.Row.RowType == DataControlRowType.DataRow) && e.Row.Cells.Count>11)
{
e.Row.Cells[8].Visible = false;
e.Row.Cells[9].Visible = false;
e.Row.Cells[10].Visible = false;
e.Row.Cells[11].Visible = false;
}
if ((e.Row.RowType == DataControlRowType.Header e.Row.RowType == DataControlRowType.DataRow) && e.Row.Cells.Count>11)
{
e.Row.Cells[8].Visible = false;
e.Row.Cells[9].Visible = false;
e.Row.Cells[10].Visible = false;
e.Row.Cells[11].Visible = false;
}
- 注意:不可以在Design time時將這些欄位的Visible設成false,因為這樣你會取得空值。
- asp.net會將這些欄位值放在viewstate內,所以如果有些資料是不能給User看到的,就不適合這樣作,如果一定要,那你就必須將viewstate 加密。
asp.net viewstat decoder
http://www.pluralsight.com/tools.aspx
Fritz OnionTool to decode the ViewState in ASP.NET 2.0 pages. This version supports display of control state as well as view state. Screenshot
Fritz OnionTool to decode the ViewState in ASP.NET pages compatible with version 1.1 of ASP.NET Screenshot
http://blogs.msdn.com/rextang/archive/2007/05/25/2868250.aspx
2008年3月20日 星期四
asp.net forms authentication Web.Config 範例
如果某一個aspx網頁不需要驗證就可以存取,可以在web.config 加上Location 這個標籤
<configuration>
<system.web>
<authentication mode="Forms" >
<forms loginUrl="login.aspx" name=".ASPNETAUTH" protection="None" path="/" timeout="20" >
</forms>
</authentication>
<!-- This section denies access to all files in this application except for those that you have not explicitly specified by using another setting. -->
<authorization>
<deny users="?" />
</authorization>
</system.web>
<!-- This section gives the unauthenticated user access to the Default1.aspx page only. It is located in the same folder as this configuration file. -->
<location path="default1.aspx">
<system.web>
<authorization>
<allow users ="*" />
</authorization>
</system.web>
</location>
<!-- This section gives the unauthenticated user access to all of the files that are stored in the Subdir1 folder. -->
<location path="subdir1">
<system.web>
<authorization>
<allow users ="*" />
</authorization>
</system.web>
</location>
</configuration>
2008年2月25日 星期一
如何在 client 端 動態修改 Custom Validator 的 error message
有User的需求是希望能用alert的方式顯示出 validator 的 錯誤訊息, Validation Summary 有一個「ShowMessageBox」property 剛好可以提供這樣的功能,但是如果你的Page上有包含 Custom Validator , 而 Custom Validator的錯誤訊息會依據不同的條件顯示的話,如何在 client 動態修改 Custom Validator 的 error message呢?
重點就是要修改 Custom Validator Client script 的 sender dom 物件,說明如下:
function fn_myValidator(sender, args)
{
sender.innerHTML = "錯誤:" + new Date().toLocaleString();
sender.errormessage = "錯誤:" + new Date().toLocaleString();
args.IsValid = false;
}
ASP.net 會將 Custom Validator render 成一個 DOM object,其中的 errormessage 屬性就是validation summary control 顯示時會去讀的資料,因此只要在Custom Validator Client script改變這個值,validation summary就會Show 出新的 error message,但是如果你希望改變Custom Validator 本身顯示在 網頁上的 error message , 就需要修改 Custom Validator 的 innerHTML or innerText。
可以參考以下兩串討論
重點就是要修改 Custom Validator Client script 的 sender dom 物件,說明如下:
function fn_myValidator(sender, args)
{
sender.innerHTML = "錯誤:" + new Date().toLocaleString();
sender.errormessage = "錯誤:" + new Date().toLocaleString();
args.IsValid = false;
}
ASP.net 會將 Custom Validator render 成一個 DOM object,其中的 errormessage 屬性就是validation summary control 顯示時會去讀的資料,因此只要在Custom Validator Client script改變這個值,validation summary就會Show 出新的 error message,但是如果你希望改變Custom Validator 本身顯示在 網頁上的 error message , 就需要修改 Custom Validator 的 innerHTML or innerText。
可以參考以下兩串討論
2008年2月4日 星期一
消失的IIS ASP.NET Tab(頁籤)
在Windows 2003 Server 上的 IIS ASP.NET Tab , 有時會莫名的失蹤,解決方法如下
http://jamesmckay.net/2008/01/missing-aspnet-tab-in-iis-on-windows-server-2003/
來取代
http://jamesmckay.net/2008/01/missing-aspnet-tab-in-iis-on-windows-server-2003/
- Stop IIS using
iisreset /stop - Open the file
C:\WINDOWS\system32\inetsrv\MetaBase.xmlin Notepad. - Find and delete the line that says
Enable32BitAppOnWin64="TRUE" - Restart IIS using
iisreset /start - If you still don’t see your ASP.NET tab,
aspnet_regiis -ishould now work.
ASP.NET Version Switcher
來取代
2007年12月11日 星期二
使用 TableAdapter 時,如何取得 stored procedure 的 return value
Visual Studio 2005的 TableAdapter ,不會回傳 stored procedure 的 return value,解決方法之一是寫一個 partial class ,然後從 CommandCollection 的 Parameters 取得 stored procedure 的 return value ,可以參考:
http://blogs.msdn.com/smartclientdata/archive/2006/08/09/693113.aspx
namespace ICP.DAL.WebATM_DSTableAdapters{ public partial class WebATM_DSTableAdapter {
public object GetReturnValue(int commandIndex) {
return ((System.Data.SqlClient.SqlParameter)this.CommandCollection[commandIndex].Parameters[0]).Value; }
}
}
範例中的commandIndex,要從 Visual Studio 2005 產生的TableAdapter source code 中的 InitCommandCollection function 找出你要的值。
http://blogs.msdn.com/smartclientdata/archive/2006/08/09/693113.aspx
namespace ICP.DAL.WebATM_DSTableAdapters{ public partial class WebATM_DSTableAdapter {
public object GetReturnValue(int commandIndex) {
return ((System.Data.SqlClient.SqlParameter)this.CommandCollection[commandIndex].Parameters[0]).Value; }
}
}
範例中的commandIndex,要從 Visual Studio 2005 產生的TableAdapter source code 中的 InitCommandCollection function 找出你要的值。
訂閱:
文章 (Atom)