2010年4月29日 星期四

GridView 刪除按鈕添加確認訊息範例

1. GridView加入編輯/刪除按鈕於最後
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />

2. 於 rowdatabound 事件加入下面程式
if (e.Row.RowType == DataControlRowType.DataRow && (e.Row.RowState & DataControlRowState.Edit) == 0)
{
LinkButton lb = e.Row.Cells[e.Row.Cells.Count - 1].Controls[2] as LinkButton;
lb.OnClientClick = "if (!confirm('確定刪除?')) return false;";
}

2010年4月13日 星期二

字串值存入XML檔案如何避免"不合法的名稱字元"訊息

參考以下函數

private string StringToXML(string XMLstring)
{
StringWriter sw = new StringWriter();
System.Xml.XmlTextWriter xmlw = new System.Xml.XmlTextWriter(sw);
xmlw.WriteString(XMLstring);
xmlw.Close();
return sw.ToString();
}

Entity Framework 建立新物件並儲存後馬上取得關聯資料

使用 CreateProxy 建立物件,不要直接 new var newmodel = _contextXXX.CreateProxy<yyy>(); ... _contextXXX.yyy.Add(newmodel); await _contextXXX.SaveC...