筆記。隨手
(移至...)
首頁
▼
2018年9月27日 星期四
判斷是否為空值(Is Nothing、IsDBNull)
C#似乎只能用等於某值來做判斷= =;;
VB
控制項
Is Nothing
IsDBNull(
資料欄位
)
C#
控制項
== null
資料欄位
== DBNull.Value
2018年9月26日 星期三
For Each / foreach
嗯....這寫法算是有點不一樣!
VB
For Each row As DataRow In GridView1.Rows
...
Next
C#
foreach (GridViewRow gvRow in gvAssignEmp.Rows)
{
...
}
Try Catch
除大小括弧外,大小寫也是容易錯的地方!
VB
Try
...
Catch ex As Exception
...
End Try
C#
try
{
...
}
catch (Exception ex)
{
...
}
2018年9月13日 星期四
DropDownList 一直跳回某個選項(亂跳)
今天發生一個很弔詭的狀況
就是在沒有指定
SelectIndex
、也沒有重新繫結
DropDownList
的狀況下
DropDownList
一直跳回某個選項
後來發現原來是因為
ListItem
的
Value
重複的關係
2018年9月12日 星期三
清除GridView資料
VB
Gridview1.DataSource =
nothing
Gridview1.DataBind()
C#
Gridview1.DataSource =
null
;
Gridview1.DataBind();
顯示行號
沒有行號真的很難除錯,沒想到換個語言開發要重新設定的時候熊熊忘記怎麼做,趁還記得趕快紀錄下來
XD
步驟如下:
1.
在功能表列上選擇
[
工具
] > [
選項
]
。
2.
展開
[
文字編輯器
]
節點,然後選取所使用語言的節點。
3.
找不到所使用語言可勾選視窗左下角
[
顯示所有設定
]
。
4.
在顯示區塊勾選
[
行號
]
。
Split 字串分割
單引號雙引號、中括弧小括弧...
我覺得我要瘋了= =
VB
str.Split(" ")(0)
C#
str.Split(
' '
)[0];
RowDataBound 的 RowType
用 RowType分門別類處理Row的事件可以避免很多莫須有的問題喔 !
protected void gvRowDataBound(object sender, GridViewRowEventArgs e)
{
switch (
e.Row.RowType
)
{
//資料列
case
DataControlRowType.DataRow
:
RowControllerDataBinding(e);
break;
}
}
2018年9月7日 星期五
SELECT CASE (SWICH CASE)
switch
(e.CommandName)
{
case
"1"
:
Console.WriteLine("Case 1");
break;
case "2":
case "3":
Console.WriteLine("Case 2.3");
break;
default:
Console.WriteLine("Case Else");
break;
}
記得要加break....(淚)
If(一般/簡寫)
[VB]
一般寫法
If
menuType = 0
Then
result = "
成立
"
Else
result = "
不成立
"
End if
簡寫
result =
If(
menuType = 0
,
"
成立
"
,
"
不成立
"
)
[C#]
一般寫法
if(menuType == 0){
result = "
成立
";
}else{
result = "
不成立
";
}
簡寫
result = menuType == 0 ? "
成立
": "
不成立
";
result = (menuType == 0 ) ? "
成立
": "
不成立
";
從 GridView 中找到 Row
RowCommand事件
GridViewRow row =
(GridViewRow)
(((Control)
e.CommandSource
).
NamingContainer
);
用同Row中的控制項
GridViewRow row =
(GridViewRow)
(((Control)
sender
).
NamingContainer
);
GridViewRow row =
(GridViewRow)
(Label1.
NamingContainer
);
VB轉型,C#泛型(FindControl)
VB
Ctype
(
row.FindControl("lblManager3")
, Label
)
.
Text = string.Empty
C#
((Label)
row.FindControl("lblManager3")
)
.
Text = string.Empty;
‹
›
首頁
查看網路版