using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
namespace ASPNETAJAXWeb.AjaxUser
{
public class AjaxUserSystem
{
public AjaxUserSystem()
{
}
/// <summary>
/// 在ASP.NET環境中彈出一個對話方塊
/// </summary>
/// <param name="response"></param>
/// <param name="message"></param>
public static void ShowDialog(HttpResponse response,string message)
{
response.Write("<script>alert(\"" + message + "\");</script>");
}
/// <summary>
/// 在ajax環境中彈出一個對話方塊
/// </summary>
/// <param name="button"></param>
/// <param name="message"></param>
public static void ShowAjaxDialog(Button button,string message)
{
ScriptManager.RegisterClientScriptBlock(button,typeof(Button),button.ClientID,message,true);
}
///
public static void ShowAjaxDialog(Page page,string message)
{
ScriptManager.RegisterClientScriptBlock(page,typeof(Page),DateTime.Now.ToString().Replace(":"," "),"alert('"+message"')",true);
}
/// <summary>
/// 根據Value屬性把清單控制項的選擇項設定為指定項
/// </summary>
/// <param name="list"></param>
/// <param name="value"></param>
public static void ListSelectedItemByValue(ListControl list,string value)
{
if(list == null) return;
///選擇項為空白
if(list.Items.Count <= 0)
{
list.SelectedIndex = -1;
return;
}
///逐項進行比較,設定選擇項
for(int i = 0; i < list.Items.Count; i++)
{
if(list.Items[i].Value == value)
{
list.SelectedIndex = i;
return;
}
}
///沒有合格選擇項
list.SelectedIndex = -1;
}
/// <summary>
/// 根據Text屬性把清單控制項的選擇項設定為指定項
/// </summary>
/// <param name="list"></param>
/// <param name="text"></param>
public static void ListSelectedItemByText(ListControl list,string text)
{
if(list == null) return;
///選擇項為空白
if(list.Items.Count <= 0)
{
list.SelectedIndex = -1;
return;
}
///逐項進行比較,設定選擇項
for(int i = 0; i < list.Items.Count; i++)
{
if(list.Items[i].Text == text)
{
list.SelectedIndex = i;
return;
}
}
///沒有合格選擇項
list.SelectedIndex = -1;
}
/// <summary>
/// 根據時間建立字串
/// </summary>
/// <returns></returns>
public static string CreateDateTimeString()
{
DateTime now = DateTime.Now;
string dtString = now.Year.ToString()
+ now.Month.ToString().PadLeft(2,'0')
+ now.Day.ToString().PadLeft(2,'0')
+ now.Hour.ToString().PadLeft(2,'0')
+ now.Minute.ToString().PadLeft(2,'0')
+ now.Second.ToString().PadLeft(2,'0')
+ now.Millisecond.ToString().PadLeft(3,'0');
return (dtString);
}
}
}
“七”樂無窮,盡在新浪新版部落格,快來體驗啊~~~請點擊進入~