2012年12月4日 星期二

取得 SqlDataSource 中Select 的結果做為DataSet 或 DataTable


取得 SqlDataSource 中Select 的結果做為DataSet 或 DataTable
'取得查詢結果
'使用DataView來取得sqlDataSource中 select 產生的結果
Dim dv As DataView = sqlDataSource1.Select(New DataSourceSelectArguments)


轉

2012年11月30日 星期五

更改DataTable欄位名稱


DataBase如果回的資料是DataSet或是DataTable
而欄位資料與要Bind的的GridView不同
如果又不想要更改Bind這邊的欄位名稱
則可以直接更改DataTable的Cloumns


o_dt = Procedures.GetDataSet.Tables[0];
DataTable dt = o_dt;
dt.Columns["ACCT_TYPE_ID"].ColumnName = "ACCT_DATA";
dt.Columns["HIDACCT_TYPE_ID"].ColumnName = "ACCT_DATA2";

2012年11月15日 星期四

調整視窗大小 asp.net



    function resizeWindow()
{
//    var width = screen.availWidth;  // 螢幕可用寬度
//    var height = screen.availHeight;    // 螢幕可用長度
//    alert('最大化視窗大小:' + width + ' * ' + height);
//    moveTo(0,0);
//    resizeTo(width, height);
//  
 


2012年11月14日 星期三

textbox 提示效果


VB.NET

textbox.Attributes.Add("Value", "請輸入帳號")
textbox.Attributes.Add("OnFocus", "if(this.value=='請輸入帳號') {this.value=''}")
textbox.Attributes.Add("OnBlur", "if(this.value==''){this.value='請輸入帳號'}")


javascript

Attributes Even

OnFocus="javascript:if(this.value=='請輸入帳號') {this.value=''}"

OnBlur="javascript:if(this.value=='') {this.value='請輸入帳號'}"

----------------------------------------------------------------------------


OnFocus="javascript:if(this.value=='請輸入帳號') {this.value=''}"

OnBlur="javascript:if(this.value==''){this.value='請輸入帳號'}">


2012年11月12日 星期一

iframe SRC 使用JavaScript

window.frames['iframeView'].location.href=document.getElementById('TextBox').value

asp.net ajax 彈不出alert對話框的解決辦法

vb 寫法ScriptManager.RegisterStartupScript(Button2, GetType(Button), "JavaScript_Sample1", "window.alert(""Hello!! Code Behind!!"")", True)
c# 寫法ScriptManager.RegisterClientScriptBlock(this.Page, typeof(Page), "message", "javascript:alert('" + "YouAre Msg" + "')", true);

-------------------------------------------

asp.net ajax 彈不出alert對話框的解決辦法

想用js腳本輸出一些提示,可是不管是用 Page.RegisterClientScriptBlock還是用 Page.RegisterStartupScript

注冊,該死的提示信息總是不出來。其實不是不出來,只是我們叫錯了它們的名字,我們只要用下面的這條語句︰

 ScriptManager.RegisterClientScriptBlock(UpdatePanel1, this.GetType(), "click", "alert('提示信息')", true);

就可以正常的彈出alert對話框了。

    注︰如果在頁面中有多個UpdatePanel,如果每個UpdatePanel的UpdateMode都是“always”[默認值]的話,

那麼你使用那個UpdatePanel的實例作為參數都可以;如果每個UpdaePanel的UpdateMode=conditional,

那麼你必須使用正在更新的那個UpdatePanel作為參數,這樣腳本才能起作用。


所以...我把msg  Function 改為..
        ///

        /// display msg : msg("")
        ///
        ///
        protected void AJAX_msg(string msgstr)
        {
            msgstr = msgstr.Replace("'", "").Replace("\n", "").Replace("\r", "").Replace('"', '”').Replace("(", "(").Replace(")", ")").Replace(";", ";");
            string javastr  = "alert('" + msgstr.ToString() + "' );\n";
            ScriptManager.RegisterClientScriptBlock(UpdatePanel1, this.GetType(), "AJAX_msg", javastr, true);
        }


///轉載 網路上

ScriptManager.RegisterClientScriptBlock(this.Page, typeof(Page), "message", "javascript:alert('" + GetMsg.GetCode("W0834") + "')", true);

ScriptManager.RegisterClientScriptBlock(this.Page, typeof(Page), "message", "javascript:alert('" + "YouAre Msg" + "')", true);

---------------------------------------

protected void Page_Load(object sender, EventArgs e)
    {
     
        string js="document.getElementById('btn').value='測試';";
        ScriptManager.RegisterClientScriptBlock(this, this.GetType(), Guid.NewGuid().ToString(), js, true);
    }
js註冊在
底下,button上面,這時候button還沒載入,會出現js錯誤
如果您在Code-Behind寫了
    protected void Page_Load(object sender, EventArgs e)
    {
         string js="document.getElementById('btn').value='測試';";
        ScriptManager.RegisterStartupScript(this,this.GetType(),Guid.NewGuid().ToString(),js,true);
    }
js註冊在button之後,
前面,因為這時候button已經載入,js的程式碼抓得到button目標,執行成功
如果是單純做頁面跳頁(window.location.href)
我都是用
RegisterClientScriptBlock,這樣使用者還沒看到畫面,頁面就已經跳頁
如果要抓取頁面上的DOM做處理,我都是用RegisterStartupScript 確保js一定抓得到頁面上的DOM

2012年11月2日 星期五

RadioButton 使用javascript 在Gridview 中單選





//GridView OnRowDataBound
protected void grid_view_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                RadioButton rb = (RadioButton)e.Row.FindControl("RadioButton1");
                rb.Attributes.Add("onclick", "judge(this)");//給RadioButton加onclick屬性
            }
        }