2008年11月14日 星期五

Create Instance By Type

本來以為這應該是 Reflection 裡的功能,沒想到找了半天找不到

原來兇手是 Activator 物件

System.Type type = this.GetType();
TSource vm = (TSource)System.Activator.CreateInstance(type, new object[] { this.UserID });
 
//TSource vm = new TSource(this.UserID);
 
foreach(DataTable dt in view.Tables)
{
    DataTable dtDest = vm.view.Tables[dt.TableName];
 
    foreach (DataRow dr in dt.Rows)
    {
        if (dr.RowState == DataRowState.Unchanged) continue;
        DataRow drDest = dtDest.NewRow();
        drDest.FillWith(dr);
        dtDest.Rows.Add(drDest);
    }
}
 
return vm;

上面的 Code 主要是要在 父類別中 Create 出子類別的 Instance

還是有更簡單的辦法呀??

2008年11月13日 星期四

ListView Insert 不能用 runat="server"

有沒有遇過神奇的事件??
最近遇到一個

就是 ListView 在 Insert Template 時會出現 神奇 Exception

ObjectDataSource“ObjectDataSource1”没有可以插入的值。请检查“values”字典是否包含值。

原始碼如下



<asp:ListView runat="server" ID="groupedList" DataSourceID="odbDetailCLD_SERIALDEF"
    EnableViewState="true" DataKeyNames="SERIALID" OnSelectedIndexChanging="groupedList_SelectedIndexChanging"
    InsertItemPosition="FirstItem" OnItemInserting="groupedList_ItemInserting">
    <LayoutTemplate>
        <table runat="server" id="table1">
            <tr runat="server" id="itemPlaceholder">
            </tr>
        </table>
    </LayoutTemplate>
    <ItemTemplate>
        <tr id="trItem" runat="server">
            <td>
                <%-- Data-bound content. --%>
                <asp:LinkButton ID="btnItemEdit" CommandName="Edit" runat="server">
                    <img id="imgItemEdit" runat="server" alt='<%#Eval("SerialName") %>' src='~/Image/edit.bmp' />
                </asp:LinkButton>
                <asp:LinkButton ID="NameLabel" runat="server" CommandName='Select' CommandArgument='<%#Eval("SerialID") %>'
                    Text='<%#Eval("SerialName") %>' />
            </td>
        </tr>
    </ItemTemplate>
    <EditItemTemplate>
        <tr id="tdEdit" runat="server">
            <td>
                <input id="Hidden1" type="hidden" runat="server" value='<%#Bind("SERIALID") %>' />
                <asp:LinkButton ID="LinkButton2" CommandName="Update" runat="server">
                    <img id="Img2" runat="server" alt='<%#Eval("SerialName") %>' src='~/Image/save.gif' />
                </asp:LinkButton>
                <asp:LinkButton ID="LinkButton1" CommandName="Cancel" runat="server">
                    <img id="imgEditEdit" runat="server" alt='<%#Eval("SerialName") %>' src='~/Image/cancel.gif' />
                </asp:LinkButton>
                系'a8t列'a6C課'bd?程'b5{名'a6W稱'ba?
                <asp:TextBox ID="txtEditSerialName" runat="server" Text='<%#Bind("SerialName") %>'></asp:TextBox>
            </td>
        </tr>
    </EditItemTemplate>
    <InsertItemTemplate>
        <tr id="tdInsert" runat="server">
            <td>
                <asp:LinkButton ID="btnSave" CommandName="Insert" runat="server">
                    <img id="imgInsertSave" runat="server" alt='<%#Eval("SerialName") %>' src='~/Image/save.gif' />
                </asp:LinkButton>
                <asp:LinkButton ID="btnCancel" CommandName="Cancel" runat="server">
                    <img id="imtInsertCancel" runat="server" alt='<%#Eval("SerialName") %>' src='~/Image/cancel.gif' />
                </asp:LinkButton>
                系'a8t列'a6C課'bd?程'b5{名'a6W稱'ba?
                <asp:TextBox ID="txtInsertSerialName" runat="server" Text='<%#Bind("SerialName") %>'></asp:TextBox>
            </td>
        </tr>
    </InsertItemTemplate>
</asp:ListView>




看出 Insert Template 那有問題了嗎??

對,我看了大約三個月吧,還是看不出來。
後來不死心將錯誤翻成英文,再請 google 大神幫忙找

"ObjectDataSource“ObjectDataSource1”没有可以插入的值。请检查“values”字典是否包含值。"
翻成
"asp.net listview there is no value to insert"

還真的給我找到了





I have found the problem.
The runat="server" on the InsertItemTemplate is causing the problem. Remove the runat="server" and
everything works fine.
Please shed some light on why this should cause a problem.
--
Philip





天殺的 runat="server"
為何 EditTemplate 可以
InsertTemplate 就不行呀~~

update 2008/11/17
神奇的事發生了。今天連 EditTemplate 也不行。
但 EditTemplate 中有兩個 Field
SerialID, SerialName
SerialID Bind 到一個 Hidden Field, SerialName Bind 到 TextBox。
為何 SerialName 就是給他變成 null >_<
把 的 runat="server" 拿掉後又好了 somebody tell me why ~~

2008年11月9日 星期日

為 VS2008 加入 Javascript 的 Intellisens

最近常在用 jQuery,但是 VS 的 Intellisens 都無法 Support
今天找到好方法

TIPS-為VS2008加入完整jQuery Intellisense

download 了 Hotfix(說明) 及 jQuery 的 Document

將 jQuery.1.2.6.js 及 jQuery.1.2.6-vsdoc.js 放在同一個目錄就行了

使用時,只要引用了 jQuery.1.2.6.js

<script src="../NewFolder1/jquery.js" type="text/javascript"></script>


這個新的 Hotfix 會自動找到說明文件,並顯示出來。


2008年11月6日 星期四

設定 ASP.NET 的暫存目錄

因為裝了 Gavotte Ramdisk 目前有大約 800 M 的空間可以用
所以想把 ASP.NET 的暫存目錄改到 RAM DISK 中
看能不能加快 COMPILE 的速度

做法為有兩種

1. 修改 machine.config
machine.config 的位置在 C:\WINDOWS\Microsoft.NET\Framework\[Framework Version]\CONFIG
[Framework Version] 為你目前用的 framework 版本。不過因為 3.5 其實本體還是用 2.0 的所以3.0, 3.5 的版本還是得修改 v2.0 裡的 machine.config

2. 修改 web.config
這位置不用說了吧

加入

<system.web>

<compilation tempDirectory="[Template Folder]" debug="true"></compilation>

</system.web>





這樣子就行了

2008年10月6日 星期一

08/10/07 DB 重大更新

LTS_CLOSEREC --> 更改 PK 為 closeno

LTS_CLOSEROLLBACK

LTS_INTENTCOUSE -> PREID 新增感興趣的課程

2008年9月15日 星期一

VS.Net 2008 開 Web 專案會 Crash

http://www.intellij.net/forums/thread.jspa?threadID=273160&tstart=0

在開啟 Web 專案時會出錯
已經發生好久了。今天終於找出解決辦法,原來這是 vs.net 的 bug 呀

以下為解決方法

The workaround is to modify web.config:
1) add reference to System.Core before all other assembly references
2) move configSections element to the end of the web.config file

照上面做就行了

2008年8月10日 星期日

How to find the max row per group in SQL without subqueries

查詢 最大值的 row

http://www.xaprb.com/blog/2007/03/14/how-to-find-the-max-row-per-group-in-sql-without-subqueries/