<<深入剖析ASP.NET组件设计>>的一个辅助类
这个书有很多缺失代码,以下是341页漏的一个ListBuilderHelper类,
/// <summary>
/// ListBuilderHelper 的摘要说明。
/// </summary>
public class ListBuilderHelper
{
private static string GenerateSelectID(Control owner)
{
return owner.UniqueID + "$select".Replace(":", "_");
}
private static string GenerateSelectValue(Control owner)
{
return owner.UniqueID + "$SELECT_VALUE".Replace(":", "_");
}
/// <summary>
/// 取得内容的包装控件,即TR
/// </summary>
/// <param name="owner">容器</param>
/// <param name="itemValue">内容值</param>
/// <param name="index">第几个</param>
/// <returns></returns>
public static Control CreateWrapperItemControl(Control owner, string itemValue, int index)
{
HtmlTableRow tr = new HtmlTableRow();
string selectID = GenerateSelectID(owner);
string postKey = GenerateSelectValue(owner);
tr.Attributes.Add("onmouseover",
string.Format("{0}_obj.pasp_HiLightItem(this,{1})",
owner.ClientID, index));
tr.Attributes.Add("onclick",
string.Format("{0}.value='{1}';{4}.pasp_ClickItem({2},'{3}')",
postKey, itemValue, selectID, itemValue, owner.ClientID + "_obj"));
owner.Controls.Add(tr); //加入容器
return tr;
}
}
/// ListBuilderHelper 的摘要说明。
/// </summary>
public class ListBuilderHelper
{
private static string GenerateSelectID(Control owner)
{
return owner.UniqueID + "$select".Replace(":", "_");
}
private static string GenerateSelectValue(Control owner)
{
return owner.UniqueID + "$SELECT_VALUE".Replace(":", "_");
}
/// <summary>
/// 取得内容的包装控件,即TR
/// </summary>
/// <param name="owner">容器</param>
/// <param name="itemValue">内容值</param>
/// <param name="index">第几个</param>
/// <returns></returns>
public static Control CreateWrapperItemControl(Control owner, string itemValue, int index)
{
HtmlTableRow tr = new HtmlTableRow();
string selectID = GenerateSelectID(owner);
string postKey = GenerateSelectValue(owner);
tr.Attributes.Add("onmouseover",
string.Format("{0}_obj.pasp_HiLightItem(this,{1})",
owner.ClientID, index));
tr.Attributes.Add("onclick",
string.Format("{0}.value='{1}';{4}.pasp_ClickItem({2},'{3}')",
postKey, itemValue, selectID, itemValue, owner.ClientID + "_obj"));
owner.Controls.Add(tr); //加入容器
return tr;
}
}