在ASP.NET 的Mobile Control是无法实现右软键的功能的所以只能自己写了
就粗粗的写了一个,
发错了,重发一次
就粗粗的写了一个,
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using System.ComponentModel;
using System.Web.Mobile;
using System.Web.UI.MobileControls;
using System.Drawing.Design;
using System.Web.UI.MobileControls.Adapters;
namespace Mobile.FrameWork.WebUI
{
事件#region 事件
/**//// <summary>
/// WMLOption ItemCommand事件的EventArgs
/// </summary>
public class WMLOptionCommandEventArgs : ListCommandEventArgs
{
public WMLOptionCommandEventArgs(WMLOptionItem item, object source) : base(item, source){}
public WMLOptionCommandEventArgs(WMLOptionItem item, object source, CommandEventArgs args) : base(item, source, args) {}
}
/**//// <summary>
/// WMLOption ItemCommand事件的委托
/// </summary>
public delegate void WMLOptionCommandEventHandler (object sender, WMLOptionCommandEventArgs e);
#endregion
WMLOptionItem 及其相关#region WMLOptionItem 及其相关
public enum WMLOptionItemType
{
Link = 0,
Command = 1,
Previous = 2,
Other = -1
}
/**//// <summary>
/// WMLOption Item
/// </summary>
public class WMLOptionItem : MobileListItem
{
/**//// <summary>
/// 构造器
/// </summary>
public WMLOptionItem():base(){}
public WMLOptionItem(string text) : base(text){}
public WMLOptionItem(string text, string value) : base(text,value){}
public WMLOptionItem(string text, string value, WMLOptionItemType type) : base(text, value)
{
this.ItemType = type;
}
private WMLOptionItemType itemtype = WMLOptionItemType.Link;
public WMLOptionItemType ItemType
{
get{ return this.itemtype; }
set{ this.itemtype = value; }
}
}
/**//// <summary>
/// WMLOption Item Colleciton
/// </summary>
[DefaultProperty("Text"),
ToolboxData("<{0}:WMLOptionItem runat=server></{0}:WMLOptionItem>")]
public class WMLOptionItemCollection : CollectionBase
{
public WMLOptionItemCollection(){}
/**//// <summary>
/// 构造器
/// </summary>
/// <param name="value"></param>
public WMLOptionItemCollection(WMLOptionItem value)
{
this.List.Add(value);
}
public WMLOptionItemCollection(WMLOptionItem[] value)
{
this.AddRange(value);
}
public WMLOptionItemCollection(WMLOptionItemCollection value)
{
this.AddRange(value);
}
/**//// <summary>
/// 索引器
/// </summary>
public WMLOptionItem this[int index]
{
get
{
return (WMLOptionItem)this.List[index];
}
set
{
this.List[index] = value;
}
}
public new void Clear()
{
this.List.Clear();
}
public void Insert(int index, WMLOptionItem item)
{
this.List.Insert(index, item);
}
public new void RemoveAt(int index)
{
this.List.RemoveAt(index);
}
public void Remove(WMLOptionItem item)
{
this.List.Remove(item);
}
public void Add(WMLOptionItem item)
{
this.List.Add(item);
}
public void AddRange(WMLOptionItem[] value)
{
foreach(WMLOptionItem item in value)
{
this.List.Add(item);
}
}
public void AddRange(WMLOptionItemCollection value)
{
foreach(WMLOptionItem item in value)
{
this.List.Add(item);
}
}
public int IndexOf(WMLOptionItem item)
{
return this.List.IndexOf(item);
}
public bool Contains(WMLOptionItem item)
{
return this.List.Contains(item);
}
public void CopyTo(WMLOptionItem[] items, int index)
{
this.List.CopyTo(items, index);
}
public new ItemEnumerator GetEnumerator()
{
return new ItemEnumerator(this);
}
public class ItemEnumerator : IEnumerator
{
private IEnumerator _enumerator;
private IEnumerable _temp;
public ItemEnumerator(WMLOptionItemCollection mappings)
{
_temp = ((IEnumerable)(mappings));
_enumerator = _temp.GetEnumerator();
}
public WMLOptionItem Current
{
get {return ((WMLOptionItem)(_enumerator.Current));}
}
object IEnumerator.Current
{
get {return _enumerator.Current;}
}
public bool MoveNext()
{
return _enumerator.MoveNext();
}
bool IEnumerator.MoveNext()
{
return _enumerator.MoveNext();
}
public void Reset()
{
_enumerator.Reset();
}
void IEnumerator.Reset()
{
_enumerator.Reset();
}
}
}
#endregion
/**//// <summary>
/// WMLOption 的摘要说明。
/// </summary>
[ParseChildren(true,"Items"),DefaultProperty("Items"),
ToolboxData("<{0}:WMLOption runat=server></{0}:WMLOption>")]
public class WMLOption : System.Web.UI.MobileControls.Panel, IPostBackEventHandler,INamingContainer
{
private WMLOptionItemCollection items = new WMLOptionItemCollection();
[PersistenceMode(PersistenceMode.InnerDefaultProperty)]
public WMLOptionItemCollection Items
{
get{ return this.items; }
set{ this.items = value; }
}
private string text;
[Bindable(true),
Category("Appearance"),
DefaultValue("Option")]
public string Text
{
get
{
return text;
}
set
{
text = value;
}
}
protected override void OnPreRender(EventArgs e)
{
this.EnableViewState = false;
base.OnPreRender (e);
}
IPostBackEventHandler 成员#region IPostBackEventHandler 成员
private static readonly object EventItemCommand = new object();
protected virtual void OnItemCommand(WMLOptionCommandEventArgs e)
{
WMLOptionCommandEventHandler onItemCommandHandler = (WMLOptionCommandEventHandler) Events[EventItemCommand];
if(onItemCommandHandler != null)
{
onItemCommandHandler(this, e);
}
}
public event WMLOptionCommandEventHandler ItemCommand
{
add{ this.Events.AddHandler(EventItemCommand, value); }
remove{ this.Events.RemoveHandler(EventItemCommand, value); }
}
public bool HasItemCommandHandler
{
get{ return (Events[EventItemCommand] != null); }
}
public void RaisePostBackEvent(string eventArgument)
{
// TODO: 添加 WMLOption.RaisePostBackEvent 实现
WMLOptionItem item = this.items[int.Parse(eventArgument)];
OnItemCommand(new WMLOptionCommandEventArgs(item, this));
}
#endregion
}
Adapter#region Adapter
/**//// <summary>
/// HtmlAdpater For WMLOptin Control
/// </summary>
public class WMLOptionHtmlAdapter : HtmlPanelAdapter
{
protected new WMLOption Control
{
get { return (WMLOption) base.Control; }
}
public override void Render(HtmlTextWriter writer)
{
this.Render((HtmlMobileTextWriter) writer);
}
/**//// <summary>
/// 重写Render
/// </summary>
/// <param name="writer"></param>
public override void Render(HtmlMobileTextWriter writer)
{
foreach(WMLOptionItem item in this.Control.Items)
{
if(item.ItemType == WMLOptionItemType.Command)
{
RenderCommand(writer, item);
}
else if(item.ItemType == WMLOptionItemType.Previous)
{
RenderPrevious(writer, item);
}
else
{
RenderLink(writer, item);
}
}
}
/**//// <summary>
/// 生成返回的链接
/// </summary>
/// <param name="writer"></param>
/// <param name="item"></param>
public void RenderPrevious(HtmlMobileTextWriter writer, WMLOptionItem item)
{
string href = Control.MobilePage.Request.RawUrl.ToString();
string html = @"<a href='{0}'>{1}</a>";
html = string.Format(html, href, item.Text);
writer.WriteLine(html);
}
/**//// <summary>
/// 生成普通的链接
/// </summary>
/// <param name="writer"></param>
/// <param name="item"></param>
public void RenderLink(HtmlMobileTextWriter writer, WMLOptionItem item)
{
//<a href={0}>{1}</a><br>
string html = "<a href="{0}">{1}</a>";
if(item.BreakAfter)
html += "<br/>";
html = string.Format(html, item.Value, item.Text);
writer.WriteLine(html);
}
/**//// <summary>
/// 生成回发的链接按钮
/// </summary>
/// <param name="writer"></param>
/// <param name="item"></param>
public void RenderCommand(HtmlMobileTextWriter writer, WMLOptionItem item)
{
this.RenderPostBackEventAsAnchor(writer,this.Control.Items.IndexOf(item).ToString(), item.Text);
}
}
/**//// <summary>
/// WMLAdapter For WMLOption Control
/// </summary>
public class WMLOptionWmlAdapter : WmlPanelAdapter
{
protected new WMLOption Control
{
get{ return (WMLOption) base.Control; }
}
public override void Render(HtmlTextWriter writer)
{
this.Render((WmlMobileTextWriter) writer);
}
/**//// <summary>
/// 重写Render
/// </summary>
/// <param name="writer"></param>
public override void Render(WmlMobileTextWriter writer)
{
foreach(WMLOptionItem item in this.Control.Items)
{
if(item.ItemType == WMLOptionItemType.Command)
this.RenderCommandItem(writer, item);
else
this.RenderLinkItem(writer, item);
}
}
protected void RenderPrevious(WmlMobileTextWriter writer, WMLOptionItem item)
{
writer.WriteLine("<do type="options" label="" + item.Text + "">");
writer.WriteLine("<prev/>");
writer.WriteLine("</do>");
}
/**//// <summary>
/// 生成普通链接
/// </summary>
/// <param name="writer"></param>
/// <param name="item"></param>
protected void RenderLinkItem(WmlMobileTextWriter writer, WMLOptionItem item)
{
string wml = "<do type="options" label="{0}">";
wml = string.Format(wml, item.Text);
writer.WriteLine(wml);
string href ="<go href="{0}" />";
href = string.Format(href, item.Value);
writer.WriteLine(href);
writer.WriteLine("</do>");
}
/**//// <summary>
/// 生成回发事件
/// </summary>
/// <param name="writer"></param>
/// <param name="item"></param>
protected void RenderCommandItem(WmlMobileTextWriter writer, WMLOptionItem item)
{
string wml = "<do type="options" label="{0}">";
wml = string.Format(wml, item.Text);
writer.WriteLine(wml);
base.Render (writer);
writer.RenderGoAction(this.Control.Text, this.Control.Items.IndexOf(item).ToString(), WmlPostFieldType.Normal, false);
writer.WriteLine("</do>");
}
#endregion
}
}
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using System.ComponentModel;
using System.Web.Mobile;
using System.Web.UI.MobileControls;
using System.Drawing.Design;
using System.Web.UI.MobileControls.Adapters;
namespace Mobile.FrameWork.WebUI
{
事件#region 事件
/**//// <summary>
/// WMLOption ItemCommand事件的EventArgs
/// </summary>
public class WMLOptionCommandEventArgs : ListCommandEventArgs
{
public WMLOptionCommandEventArgs(WMLOptionItem item, object source) : base(item, source){}
public WMLOptionCommandEventArgs(WMLOptionItem item, object source, CommandEventArgs args) : base(item, source, args) {}
}
/**//// <summary>
/// WMLOption ItemCommand事件的委托
/// </summary>
public delegate void WMLOptionCommandEventHandler (object sender, WMLOptionCommandEventArgs e);
#endregion
WMLOptionItem 及其相关#region WMLOptionItem 及其相关
public enum WMLOptionItemType
{
Link = 0,
Command = 1,
Previous = 2,
Other = -1
}
/**//// <summary>
/// WMLOption Item
/// </summary>
public class WMLOptionItem : MobileListItem
{
/**//// <summary>
/// 构造器
/// </summary>
public WMLOptionItem():base(){}
public WMLOptionItem(string text) : base(text){}
public WMLOptionItem(string text, string value) : base(text,value){}
public WMLOptionItem(string text, string value, WMLOptionItemType type) : base(text, value)
{
this.ItemType = type;
}
private WMLOptionItemType itemtype = WMLOptionItemType.Link;
public WMLOptionItemType ItemType
{
get{ return this.itemtype; }
set{ this.itemtype = value; }
}
}
/**//// <summary>
/// WMLOption Item Colleciton
/// </summary>
[DefaultProperty("Text"),
ToolboxData("<{0}:WMLOptionItem runat=server></{0}:WMLOptionItem>")]
public class WMLOptionItemCollection : CollectionBase
{
public WMLOptionItemCollection(){}
/**//// <summary>
/// 构造器
/// </summary>
/// <param name="value"></param>
public WMLOptionItemCollection(WMLOptionItem value)
{
this.List.Add(value);
}
public WMLOptionItemCollection(WMLOptionItem[] value)
{
this.AddRange(value);
}
public WMLOptionItemCollection(WMLOptionItemCollection value)
{
this.AddRange(value);
}
/**//// <summary>
/// 索引器
/// </summary>
public WMLOptionItem this[int index]
{
get
{
return (WMLOptionItem)this.List[index];
}
set
{
this.List[index] = value;
}
}
public new void Clear()
{
this.List.Clear();
}
public void Insert(int index, WMLOptionItem item)
{
this.List.Insert(index, item);
}
public new void RemoveAt(int index)
{
this.List.RemoveAt(index);
}
public void Remove(WMLOptionItem item)
{
this.List.Remove(item);
}
public void Add(WMLOptionItem item)
{
this.List.Add(item);
}
public void AddRange(WMLOptionItem[] value)
{
foreach(WMLOptionItem item in value)
{
this.List.Add(item);
}
}
public void AddRange(WMLOptionItemCollection value)
{
foreach(WMLOptionItem item in value)
{
this.List.Add(item);
}
}
public int IndexOf(WMLOptionItem item)
{
return this.List.IndexOf(item);
}
public bool Contains(WMLOptionItem item)
{
return this.List.Contains(item);
}
public void CopyTo(WMLOptionItem[] items, int index)
{
this.List.CopyTo(items, index);
}
public new ItemEnumerator GetEnumerator()
{
return new ItemEnumerator(this);
}
public class ItemEnumerator : IEnumerator
{
private IEnumerator _enumerator;
private IEnumerable _temp;
public ItemEnumerator(WMLOptionItemCollection mappings)
{
_temp = ((IEnumerable)(mappings));
_enumerator = _temp.GetEnumerator();
}
public WMLOptionItem Current
{
get {return ((WMLOptionItem)(_enumerator.Current));}
}
object IEnumerator.Current
{
get {return _enumerator.Current;}
}
public bool MoveNext()
{
return _enumerator.MoveNext();
}
bool IEnumerator.MoveNext()
{
return _enumerator.MoveNext();
}
public void Reset()
{
_enumerator.Reset();
}
void IEnumerator.Reset()
{
_enumerator.Reset();
}
}
}
#endregion
/**//// <summary>
/// WMLOption 的摘要说明。
/// </summary>
[ParseChildren(true,"Items"),DefaultProperty("Items"),
ToolboxData("<{0}:WMLOption runat=server></{0}:WMLOption>")]
public class WMLOption : System.Web.UI.MobileControls.Panel, IPostBackEventHandler,INamingContainer
{
private WMLOptionItemCollection items = new WMLOptionItemCollection();
[PersistenceMode(PersistenceMode.InnerDefaultProperty)]
public WMLOptionItemCollection Items
{
get{ return this.items; }
set{ this.items = value; }
}
private string text;
[Bindable(true),
Category("Appearance"),
DefaultValue("Option")]
public string Text
{
get
{
return text;
}
set
{
text = value;
}
}
protected override void OnPreRender(EventArgs e)
{
this.EnableViewState = false;
base.OnPreRender (e);
}
IPostBackEventHandler 成员#region IPostBackEventHandler 成员
private static readonly object EventItemCommand = new object();
protected virtual void OnItemCommand(WMLOptionCommandEventArgs e)
{
WMLOptionCommandEventHandler onItemCommandHandler = (WMLOptionCommandEventHandler) Events[EventItemCommand];
if(onItemCommandHandler != null)
{
onItemCommandHandler(this, e);
}
}
public event WMLOptionCommandEventHandler ItemCommand
{
add{ this.Events.AddHandler(EventItemCommand, value); }
remove{ this.Events.RemoveHandler(EventItemCommand, value); }
}
public bool HasItemCommandHandler
{
get{ return (Events[EventItemCommand] != null); }
}
public void RaisePostBackEvent(string eventArgument)
{
// TODO: 添加 WMLOption.RaisePostBackEvent 实现
WMLOptionItem item = this.items[int.Parse(eventArgument)];
OnItemCommand(new WMLOptionCommandEventArgs(item, this));
}
#endregion
}
Adapter#region Adapter
/**//// <summary>
/// HtmlAdpater For WMLOptin Control
/// </summary>
public class WMLOptionHtmlAdapter : HtmlPanelAdapter
{
protected new WMLOption Control
{
get { return (WMLOption) base.Control; }
}
public override void Render(HtmlTextWriter writer)
{
this.Render((HtmlMobileTextWriter) writer);
}
/**//// <summary>
/// 重写Render
/// </summary>
/// <param name="writer"></param>
public override void Render(HtmlMobileTextWriter writer)
{
foreach(WMLOptionItem item in this.Control.Items)
{
if(item.ItemType == WMLOptionItemType.Command)
{
RenderCommand(writer, item);
}
else if(item.ItemType == WMLOptionItemType.Previous)
{
RenderPrevious(writer, item);
}
else
{
RenderLink(writer, item);
}
}
}
/**//// <summary>
/// 生成返回的链接
/// </summary>
/// <param name="writer"></param>
/// <param name="item"></param>
public void RenderPrevious(HtmlMobileTextWriter writer, WMLOptionItem item)
{
string href = Control.MobilePage.Request.RawUrl.ToString();
string html = @"<a href='{0}'>{1}</a>";
html = string.Format(html, href, item.Text);
writer.WriteLine(html);
}
/**//// <summary>
/// 生成普通的链接
/// </summary>
/// <param name="writer"></param>
/// <param name="item"></param>
public void RenderLink(HtmlMobileTextWriter writer, WMLOptionItem item)
{
//<a href={0}>{1}</a><br>
string html = "<a href="{0}">{1}</a>";
if(item.BreakAfter)
html += "<br/>";
html = string.Format(html, item.Value, item.Text);
writer.WriteLine(html);
}
/**//// <summary>
/// 生成回发的链接按钮
/// </summary>
/// <param name="writer"></param>
/// <param name="item"></param>
public void RenderCommand(HtmlMobileTextWriter writer, WMLOptionItem item)
{
this.RenderPostBackEventAsAnchor(writer,this.Control.Items.IndexOf(item).ToString(), item.Text);
}
}
/**//// <summary>
/// WMLAdapter For WMLOption Control
/// </summary>
public class WMLOptionWmlAdapter : WmlPanelAdapter
{
protected new WMLOption Control
{
get{ return (WMLOption) base.Control; }
}
public override void Render(HtmlTextWriter writer)
{
this.Render((WmlMobileTextWriter) writer);
}
/**//// <summary>
/// 重写Render
/// </summary>
/// <param name="writer"></param>
public override void Render(WmlMobileTextWriter writer)
{
foreach(WMLOptionItem item in this.Control.Items)
{
if(item.ItemType == WMLOptionItemType.Command)
this.RenderCommandItem(writer, item);
else
this.RenderLinkItem(writer, item);
}
}
protected void RenderPrevious(WmlMobileTextWriter writer, WMLOptionItem item)
{
writer.WriteLine("<do type="options" label="" + item.Text + "">");
writer.WriteLine("<prev/>");
writer.WriteLine("</do>");
}
/**//// <summary>
/// 生成普通链接
/// </summary>
/// <param name="writer"></param>
/// <param name="item"></param>
protected void RenderLinkItem(WmlMobileTextWriter writer, WMLOptionItem item)
{
string wml = "<do type="options" label="{0}">";
wml = string.Format(wml, item.Text);
writer.WriteLine(wml);
string href ="<go href="{0}" />";
href = string.Format(href, item.Value);
writer.WriteLine(href);
writer.WriteLine("</do>");
}
/**//// <summary>
/// 生成回发事件
/// </summary>
/// <param name="writer"></param>
/// <param name="item"></param>
protected void RenderCommandItem(WmlMobileTextWriter writer, WMLOptionItem item)
{
string wml = "<do type="options" label="{0}">";
wml = string.Format(wml, item.Text);
writer.WriteLine(wml);
base.Render (writer);
writer.RenderGoAction(this.Control.Text, this.Control.Items.IndexOf(item).ToString(), WmlPostFieldType.Normal, false);
writer.WriteLine("</do>");
}
#endregion
}
}
发错了,重发一次