2008年9月14日 星期日

Email 簡體轉繁體寄送

Dim objMail As New MailMessage

' 用UTF8 編碼

objMail.BodyEncoding = Encoding.UTF8

......

' 轉為繁體
objMail.Subject = StrConv(v_subject, VbStrConv.TraditionalChinese, 1033)
objMail.Body = StrConv(v_body, VbStrConv.TraditionalChinese, 1033)

2008年7月25日 星期五

Error code 2738

安裝 del.icio.us 時出現了: Error code 2738

執行 regsvr32 vbscript.dll 後就可以了. (一針見血)

 

參考資料: http://discussions.europe.nokia.com/discussions/board/message?board.id=swupdate&thread.id=27261

Could not access network location %USERPROFILE%\

我的XP每次安裝軟體, 總是遇到這個問題:

Could not access network location %USERPROFILE%\...

困擾好久, 只能暫時登錄 Administrator 安裝完再重新登錄.

原來我之前regedit並未完全作完修正動作:

1.

HKEY_CURRENT_USER \ Software \ Microsoft \ Windows \ CurentVersion \ Explorer \ User Shell Folders

2. 確定在右視窗有 REG_EXPAND_SZ type. 不是 REG_SZ type 的值.

3. 我的情形是: 名稱: Startup 類型: REG_SZ 資料:

%USERPROFILE%\「開始」功能表\程式集\啟動, 刪除後右鍵->新增一個同名稱和資料的:可擴充字串值(REG_EXPAND_SZ).

4. 匯出User Shell Folders 並執行之.

參考資料來源:

http://windowsxp.mvps.org/msi1606.htm

2008年6月19日 星期四

VS 2005 and VS 2008 Tip

第一次使用Visual Studio 2005 或 2008 都會有偏好語言選擇項,

事後要修改可以在:

工具 -> 匯入和匯出設定 中重設.

2008年4月10日 星期四

Javascript function : trim() - 自訂

Javascript function : trim() - 自訂

Javascript 沒有 trim 這個function,
但有人自己寫的:
(看不懂的的東東, 但很好用的功能)

//去除字串左邊的空白虛格
function ltrim(instr){
return instr.replace(/^[\s]*/gi,"");
}

//去除字串右邊的空白虛格
function rtrim(instr){
return instr.replace(/[\s]*$/gi,"");
}

//去除字串前後的空白虛格
function trim(instr){
instr = ltrim(instr);
instr = rtrim(instr);
return instr;
}

Javascript function : substring()

Javascript function : substring()

有時候功能太多也是個問題,
每次用到都有些迷惑:

經測試:
alert('ABCDEFGH'.substring(3,1)); = 'BC'
alert('ABCDEFGH'.substring(2,4)); = 'CD'
alert('ABCDEFGH'.substring(5,2)); = 'CDE'
alert('ABCDEFGH'.substring(1,3)); = 'BC'
alert('ABCDEFGH'.substring(4,2)); = 'CD'
alert('ABCDEFGH'.substring(2,5)); = 'CDE'

結論是:
substring(3,1) = substring(1,3)
從小數字(0開始)到大數字(1開始)止

01234567(小)
ABCDEFGH
12345678(大)

好天才的設計師, 弄出這種指令!!

2008年4月9日 星期三

datagrid中n的倍數列變底色

datagrid中5的倍數列變底色:

忘了在那看到:

請試著在 DataGrid 的 ItemCreated 中加入以下程式:
C#:

private void DataGrid1_ItemCreated(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e) {
if ( (e.Item.ItemIndex%5) == 4 ) {
foreach( TableCell tc in e.Item.Cells )
tc.BackColor = Color.Red;
}
}

VB:

Private Sub dg1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles dg1.ItemDataBound
If ((e.Item.ItemIndex + 1) Mod 10 = 0) Then
e.Item.BackColor = Color.Red
End If
End Sub


後來我有用到的是在datagrid DataBind 之後:
去設定背景顏色:

For i = 0 To grdResults.Items.Count - 1
Dim state As String = CType(grdResults.Items(i).Cells(0).FindControl("field_order"), Label).Text.Trim
If state = "1" Then
grdResults.Items(i).BackColor = Color.LightGray
End If
Next i

其中field_order欄位內資料事先已存入"1" 或 "0"
也可以用來enabled/disabled欄位:

For i = 0 To grdResults.Items.Count - 1
v_cbo = CType(grdResults.Items(i).Cells(6).FindControl("field_curr"), DropDownList)
v_cbo.Enabled = False
Dim v_prc As TextBox = CType(grdResults.Items(i).Cells(7).FindControl("field_prc"), TextBox)
v_prc.Enabled = False
Next

另外listitem改變顏色方式:
aspx:

<select id="Select1" onchange="On_Change" runat="server" onserverchange="Server_Change">
</select>

page_load:

Select1.Items.Clear()
Select1.Items.Add(New ListItem("11111", "11111"))
Select1.Items.Add(New ListItem("22222", "22222"))
Select1.Items.Add(New ListItem("33333", "33333"))
Select1.Items.Add(New ListItem("44444", "44444"))
Select1.Items.Add(New ListItem("55555", "55555"))
Select1.Items.Add(New ListItem("66666", "66666"))

Dim ii As ListItem
Dim j As Integer = 1
For Each ii In Select1.Items
If (j Mod 3 = 0) Then
ii.Attributes("style") = "COLOR: Red;" + " BACKGROUND-COLOR: White; "
End If
j = j + 1
Next

如何在 aspx 的 datagrid 中呼叫Javascript function並傳參數

如何在 aspx 的 datagrid 中呼叫Javascript function並傳參數:

1. 先在datagrid (.aspx) 的方法中定義:
(使用 OnItemDataBound 方法以提供 ItemDataBound 事件的自訂處理常式).

...
<asp:datagrid id="grdResults" runat="server" OnItemDataBound="Item_Bound"
...
<asp:TemplateColumn SortExpression="rma_ioutno" HeaderText="Sales Slip">
<HeaderStyle HorizontalAlign="Center"></HeaderStyle>
<ItemStyle HorizontalAlign="Center"></ItemStyle>
<ItemTemplate>
<asp:HyperLink id="xxx" STYLE='cursor:hand' runat="server" ImageUrl="../images/html.gif"></asp:HyperLink>
<asp:textbox runat="server" Width="90px" Text='<%# Container.DataItem("field_no") %>' ID="field_no" />
</ItemTemplate>
</asp:TemplateColumn>
...


2. Item_Bound() 自訂處理常式(.aspx.vb):

Sub Item_Bound(ByVal sender As Object, ByVal e As DataGridItemEventArgs)
Dim Hk As System.Web.UI.WebControls.HyperLink
Hk = CType(e.Item.FindControl("xxx"), HyperLink)
Dim TXTsn As System.Web.UI.WebControls.TextBox
TXTsn = CType(e.Item.FindControl("field_sno"), TextBox)
Dim TXTio As System.Web.UI.WebControls.TextBox
TXTio = CType(e.Item.FindControl("field_no"), TextBox)
Dim vsn As String = "zzz"
Dim vio As String = "zzz"
If Not (IsNothing(TXTsn)) Then
vsn = TXTsn.ClientID
End If
If Not (IsNothing(TXTio)) Then
vio = TXTio.ClientID
End If
If Not (IsNothing(Hk)) Then
Hk.Attributes.Add("onclick", "atrun(" & e.Item.ItemIndex + 1 & ",'" & vsn & "'," & vio & ")")
End If
End Sub


3. 回到.aspx中寫下Javascript atrun() function:

function atrun(v_itxt, x2, x3) {
var v_cus = document.frmServer.txtcus.value;
var v_pno = escape(grdResults.rows(v_itxt).cells(3).innerText);
var v_sno = document.frmServer.elements(x2).value;
seekiout(v_cus, v_pno, v_sno, x3.id);
}
function seekiout(v_cus, v_pno, v_sn, v_itxt) {
if (v_cus && v_pno) {
popwin = window.open('ioseek.aspx?v_cus='+v_cus+'&v_pno='+v_pno+'&v_sn='+v_sn+'&v_itxt='+v_itxt,'popwin','scrollbars=yes,width=500,height=600');
popwin.focus();
} else {
alert("Customer or Product empty!!");
}
}


如此便可以在datagrid中點選超連結另開ioseek.aspx視窗,
並傳入該行不同欄位資料給ioseek.aspx視窗.

ASPX 欄位顯示格式化

ASPX 欄位顯示格式化


BoundColumn : DataFormatString="{0:n2}"
Label : <%# DataBinder.Eval(Container.DataItem, "field_prc", "{0:n2}") %>
textbox : Text='<%# DataBinder.Eval(Container.DataItem, "field_prc", "{0:n2}") %>'
textbox : style="text-align:right"

用Javascript隱藏Table及物件

用Javascript隱藏Table及其內容:


function distot(v_chk) {
if (v_chk.checked) {
Table3.style.display="none";
}else{
Table3.style.display="block";
}
}

function distot1() {
var v_chk1 = document.frmServer.rb1
var v_chk2 = document.frmServer.rb2
if (v_chk1.checked) {
document.getElementById("Label21").style.display = ''; document.getElementById("cbo_line").style.display = '';
}else{
document.getElementById("Label21").style.display = 'none'; document.getElementById("cbo_line").style.display = 'none'; }
}