恭皓's profile心天地分享PhotosBlogListsMore ![]() | Help |
心天地分享
|
July 30 依「權限」顯示「不同選單」※ 第一層 Web.config 檔
◇ 在 system.web 標籤下定義「預設siteMap提供器」且 securityTrimmingEnabled 屬性必須為 True <siteMap defaultProvider="SiteMapProvider" enabled="true"> <providers> <add name="SiteMapProvider" type="System.Web.XmlSiteMapProvider " siteMapFile="Web.sitemap" securityTrimmingEnabled="true" /> </providers> </siteMap> ◇ 在 system.web 標籤下定義 authorization 標籤 <authorization> <deny users="?" /> </authorization> ※ Web.sitemap 檔
◇ roles 屬性必須填入「群組名稱」。 ◇ 首頁 roles = "*" ◇ 有兩個以上群組時,以「,」分隔設定 ※ 資料夾中控制的 Web.config 檔
◇ 分別設定權限 <?xml version="1.0" encoding="utf-8"?> <configuration> <system.web> <authorization> <allow roles="控制群" /> <allow roles="自訂組" /> <deny users="*"/> </authorization> </system.web> </configuration> June 17 使用SqlCommand呼叫「預存程序」Using MyConnection As SqlConnection = New SqlConnection(MyConnectionString)
Dim MyCommand As SqlCommand = New SqlCommand("預存程序名稱", MyConnection) MyCommand.CommandType = CommandType.StoredProcedure Dim MyPara1 As SqlParameter = New SqlParameter("@預存參數", 預存資料型態, 預存資料長度)
MyPara1.Value = 指定的值 MyCommand.Parameters.Add(MyPara1) Dim MyReturn As SqlParameter = New SqlParameter("@預存的返回", 預存資料型態, 預存資料長度)
MyCommand.Parameters.Add(MyReturn) ' 指定參數方向為:返回值 MyCommand.Parameters("@MyReturn").Direction = ParameterDirection.ReturnValue MyConnection.Open()
Dim MyReader As SqlDataReader = MyCommand.ExecuteReader MyReader.Close()
MyConnection.Close() ' 返回值可由 MyReturn.Value 取得
End Using June 09 JavaScript使用※ 開啟一個新視窗
語法:window.open('網址', '視窗名稱', '規格')
範例:window.open('http://hinet.net', '', 'left=350,top=300,height=170,width=260')
※ 更新母視窗的資料
語法:opener.location.reload(true);
※ 關閉視窗
語法:self.close();
FormView控制元件※ DefaultMode(預設模式):ReadOnly(唯讀)、Edit(可編輯)、Insert(可新增)
GridView控制元件※ TemplateField( 樣板 ) 類別
◇ HeaderText:欄位開頭的文字
◇ ItemTemplate:這裡可以「設計樣式」與要擺入的「控制元件」
◇ 當樣板中擺入控件後,可使用「物件.DataBinding」
範例:LinkButton2_DataBinding(ByVal sender As Object, ByVal e As System.EventArgs)
// 取得此 LinkButton 物件
Dim ThisLinkButton As LinkButton = CType(sender, LinkButton) // 取得此 GridViewRow 物件 Dim ThisRow As GridViewRow = CType(ThisLinkButton.NamingContainer, GridViewRow) // 使用 Eval 方法取得「欄位值」並指派給 LinkButton 的 ToolTip 屬性 Dim UserName As String = Eval("UserName") ThisLinkButton.ToolTip = UserName -------------------------------------------------------------------------------------------------------------------------------------------------------
※ RowDataBound 事件
GridView_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs)
// 當控制列的型態是「DataRow」時,進行處理
If (e.Row.RowType = DataControlRowType.DataRow) Then
// 將找到的 LinkButton 控件指定給 oLinkButton
Dim ThisLinkButton as LinkButton = e.Row.FindControl(LinkButton1)
// 為 oLinkButton 增加一個 onclick 屬性,其為開啟一個新頁面,並將 ToolTip 值傳給它當參數
ThisLinkButton.Attributes.Add("onclick", _
String.Format("window.open('網址?參數={0}')", ThisLinkButton.ToolTip) )
End If
-------------------------------------------------------------------------------------------------------------------------------------------------------
※ RowCreated 事件
GridView_RowCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs)
If (e.Row.RowType = DataControlRowType.Header) Then e.Row.Cells.RemoveAt(4) e.Row.Cells(3).ColumnSpan = 2 e.Row.Cells.RemoveAt(7) e.Row.Cells(6).ColumnSpan = 2 End If 物件.Attributes.Add()物件ID.Attributes.Add( "物件屬性", 值 )
範例:設定「文字方塊」的「onkeypress」屬性為一段JavaScript,其為按「Enter鍵」後,執行_doPostBack方法
TextBox1.Attributes.Add( "onkeyPress", "javascript:if(event.keyCode)==13 _doPostBack() )"
<%# %>與Eval一、簡單屬性:<%# custID %>
二、集 合:<asp:ListBox id="List1" datasource='<%# myArray %>' runat="server"> 三、運算 式:<%# (customer.FirstName + " " + customer.LastName) %> 四、方法結果:<%# GetBalance(custID) %> --------------------------------------------------------------------------------------------------------------------------------------
◇ Eval(字串表示式)【DataBinder.Eval】
DataBinder.Eval(Container.DataItem, "某資料欄名A", 格式).ToString() → 取出資料欄名A中的資料
Eval("某資料欄名A").ToString() → 意思同上
範例:
訂購日期: <%# DataBinder.Eval(Container.DataItem, "日期時間值", "{0:d}") %>
數量: <%# DataBinder.Eval(Container.DataItem, "整數值", "{0:N2}") %> 項目: <%# DataBinder.Eval(Container.DataItem, "字串值") %> 訂購日期: <asp:CheckBox id=chk1 Checked='<%# DataBinder.Eval(Container.DataItem, "布林值") %> |
|||
|
|