2011年2月22日 星期二

GridView CommandArgument is Empty

當CommandArgument == ""的時候,可以使用下面的屬性來設定asp伺服器元件
(LinkButton , CommandButton等...)

CommandArgument='<%# Container.DataItemIndex%>'
(取出來的值是代表目前的row在整個gridview裡的index)

CommandArgument='<%# Container.DisplayIndex %>'
(取出來的值是代表目前的row顯示在gridview裡的index)

ex.
<asp:LinkButton ID="lbtnSend" runat="server" CausesValidation="False" CssClass="btnlink"
CommandName="Send" Text="發信" CommandArgument='<%# Container.DisplayIndex %>'></asp:LinkButton>

2011年2月8日 星期二

取得控制項在螢幕上的絕對位置

Point p = control.PointToScreen(new Point(0, 0));

2010年12月29日 星期三

SystemException 無法建立 AppDomain

執行MVC專案時出現 Failed to create AppDomain
後來建立一個新的MVC專案也是同樣的問題

結果原因似乎是出現在"小紅傘"身上,移除後就正常了
之後再將"小紅傘"重新安裝回去

環境:vs2010, mvc2 web 應用程式

2010年12月2日 星期四

UMLet執行失敗

執行UMLet,在Win7中明明已經裝了java還出現
You have to install Java (www.java.com) to run UMLet!

解決方法是在環境變數

電腦 -> 右鍵 -> 內容 -> 進階系統設定 -> 環境變數
在使用者變數 -> 新增 ->
變數名稱(N) : PATH
變數值(V):C:\Program Files (x86)\Java\jre6\bin

確定後重新開機~ 完成!

2010年11月5日 星期五

使用FFmpeg將影像轉成H264

用FFmpeg在command line下將任何格式轉成h264
畫質及速度都還不錯的參數

string paras = string.Format("-i \"{0}\" -crf 35.0 -vcodec libx264 -acodec libfaac -ar 48000 -ab 128kb -coder 1 -flags +loop -cmp +chroma -partitions +parti4x4+partp8x8+partb8x8 -me_method hex -subq 6 -me_range 16 -g 250 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -b_strategy 1 -threads 0 \"{1}\"", _srcFilePath, _destFilePath);

上面是c#的code
命令列的話當然就是
c:\> ffmpeg.exe -i "c:\src.avi" -crf 35.0 -vcodec libx264 -acodec libfaac -ar 48000 -ab 128kb -coder 1 -flags +loop -cmp +chroma -partitions +parti4x4+partp8x8+partb8x8 -me_method hex -subq 6 -me_range 16 -g 250 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -b_strategy 1 -threads 0 "c:\dest.mp4"

粗體字的部分自行換掉吧

ps. _destFilePath 副檔名記得設為.mp4

如果參數使用失敗的話,可能是版本問題?!
這裡放上我測試過的
FFmpeg dowload

2010年9月14日 星期二

在程式中變更ConnectionString

通常使用Membership這類物件時,會建立web.config or app.config來設定連線字串及MembershipProvider
以下範例可以動態的在程式碼中變更資料庫連線字串


private void SetProviderConnectionString(string connectionString)
{
// Set private property of Membership, Role and Profile providers.
//Do not try this at home!!
FieldInfo connectionStringField = Membership.Provider.GetType().GetField("_sqlConnectionString", BindingFlags.Instance | BindingFlags.NonPublic);

if (connectionStringField != null)
connectionStringField.SetValue(Membership.Provider, connectionString);

FieldInfo roleField = Roles.Provider.GetType().GetField("_sqlConnectionString", BindingFlags.Instance | BindingFlags.NonPublic);

if (roleField != null)
roleField.SetValue(Roles.Provider, connectionString);

FieldInfo profileField = ProfileManager.Provider.GetType().GetField("_sqlConnectionString", BindingFlags.Instance | BindingFlags.NonPublic);

if (profileField != null)
profileField.SetValue(ProfileManager.Provider, connectionString);
}

2010年9月7日 星期二

解決MsSQL資料庫重新命名失敗問題

使用Microsoft SQL Server Management Studio
右鍵點選要Rename的資料庫...結果出現5030錯誤
這表示資料庫正被使用中(大概XD)

所以,一個比較直覺的想法就是將資料庫停用,強迫所有使用者斷線
然後再重新將資料庫啟用

首先在要Rename的資料庫(右鍵)->工作->卸離,勾選卸除連接,然後按確定
這樣database就會被卸載了。

然後資料庫(右鍵)->附加->選擇剛剛被卸載的資料庫檔案,將資料庫掛回去
這樣database應該就可以rename了。

ps. sp_who這個SQL指令可以查出database正在被那些程序使用