解决方案 »
- 关于C#缓存
- 有没有大侠用过IEWord这个控件呀?请问在asp.net中如何使用,能提供点示例吗?
- 就这点分了,各位大哥。asp.net 2.0 一个本地化的问题
- “报表文件路径错误"散分
- 为什么打不开aspx.cs的代码编辑 ,谢谢!
- js的日历构件被asp.net控件挡住了怎么办??
- WEB.Config问题,还能解决吗?高分求助
- 简单问题,怎样让label中的控件分行显示
- 请问如何在静态页中加入留言功能??
- web导出Excel并插入图片
- MVC 中@Html.DropDownListFor() 设置选中项 这么不好使 ?
- 为什么打开WEB程序提示 “打开 Web http://localhost:4814 时出错”
{ private string mstrEmptyText = "暂无数据!";//DataSource为空的时候显示的字
private IList dataSource;
private int intItemCount;
private int _Top = 10;
private string _StrWhere = "IsLock=0";
private string _FiledOrder = "id desc";
private string _flied = "*";
private string _table = "Article";
private Boolean _IsPra = false;
private string _Swhere = "";
private Boolean _IsCache = false;
private string _CacheName = ""; /// <summary>
/// 缓存名字
/// </summary>
[Bindable(true), Category("Data"), DefaultValue(""), Description("缓存名字")]
public string CacheName
{
get { return _CacheName; }
set { _CacheName = value; }
}
/// <summary>
/// 是否缓存
/// </summary>
[Bindable(true), Category("Data"), DefaultValue(false), Description("是否缓存默认flase")]
public Boolean IsCache
{
get { return _IsCache; }
set { _IsCache = value; }
} /// <summary>
/// 数据库表名
/// </summary>
[Bindable(true), Category("Data"), DefaultValue("Article"), Description("数据库表名")]
public string Table
{
get { return _table; }
set { _table = value; }
}
/// <summary>
/// 要显示的字段
/// </summary>
[Bindable(true), Category("Data"), DefaultValue("Title"), Description("显示的字段,请用,隔开")]
public string Flied
{
get { return _flied; }
set { _flied = value; }
}
/// <summary>
/// 显示的条数
/// </summary>
[Bindable(true), Category("Data"), DefaultValue("10"), Description("显示记录数")]
public int Top
{
get { return _Top; }
set { _Top = value; }
}
/// <summary>
/// 查询条件
/// </summary>
[Bindable(true), Category("Data"), DefaultValue("IsLock=0"), Description("查询条件")]
public string StrWhere
{
get { return _StrWhere; }
set { _StrWhere = value; }
}
/// <summary>
/// 排序字段
/// </summary>
[Bindable(true), Category("Data"), DefaultValue("id desc"), Description("排序字段")]
public string FiledOrder
{
get { return _FiledOrder; }
set { _FiledOrder = value; }
}
/// <summary>
/// 是否查询子类别
/// </summary>
[Bindable(true), Category("Data"), DefaultValue(false), Description("是否查询子类别")]
public Boolean IsPra
{
get { return _IsPra; }
set { _IsPra = value; }
}
/// <summary>
/// 子类别查询条件
/// </summary>
[Bindable(true), Category("Data"), DefaultValue(""), Description("查询子类别")]
public string Swhere
{
get { return _Swhere; }
set { _Swhere = value; }
} /**/
/// <summary>
/// 数据源为空时显示的文本,默认为空
/// </summary>
public string EmptyText
{
set { mstrEmptyText = value; }
}
/**/
/// <summary>
/// 设置 MyRepeater 控件的数据源。
/// 可以接受 DataSet、DataTable和所以实现了IList借口的数据源。
/// </summary>
public override object DataSource
{
set
{
try
{
if (value == null)
{
dataSource = null;
intItemCount = 0;
}
else if (value.GetType() == typeof(DataTable))//数据源是DataTable,转化为IList
{
dataSource = (IList)(new DataView((DataTable)value));
intItemCount = dataSource.Count;
}
else if (value.GetType() == typeof(DataSet))//数据源是DataSet,转化为IList
{
dataSource = (IList)(new DataView(((DataSet)value).Tables[0]));
intItemCount = dataSource.Count;
}
else
{
dataSource = (IList)value;
intItemCount = dataSource.Count;
}
}
catch
{
dataSource = null;
intItemCount = 0;
}
} } protected override void OnLoad(EventArgs e)
{
if (Visible)
{
this.DataBind();
}
} protected override void Render(System.Web.UI.HtmlTextWriter writer)
{
if (intItemCount == 0)//数据源为空
{
writer.Write(mstrEmptyText);
return;
}
base.Render(writer);
} protected override void OnDataBinding(EventArgs e)
{
DataSet ds = null;
StringBuilder str = new StringBuilder(); str.Append("select top " + _Top + " " + _flied + " from " + _table + " where " + _StrWhere + " order by " + _FiledOrder + "");
if (_IsCache)
{
ds = DotNet.Common.DataCache.GetCache(_CacheName) as DataSet;
if (ds != null)
{
ds = DotNet.Common.DataCache.GetCache(_CacheName) as DataSet;
}
else
{
DbHepler db = new DbHepler();
ds = db.Query(str.ToString());
DotNet.Common.DataCache.SetCache(_CacheName, ds, DateTime.Now.AddMinutes(600), TimeSpan.Zero);
}
}
else
{
DbHepler db = new DbHepler();
ds = db.Query(str.ToString());
}
base.DataSource = dataSource = (IList)(new DataView(((DataSet)(ds)).Tables[0]));
intItemCount = dataSource.Count;
base.OnDataBinding(e);
}
}
void head_index12345()
{
for (int i=1;i<6;i++)
{
int id = string.IsNullOrEmpty(Request.QueryString["id"]) ? 0 : int.Parse(Request.QueryString["id"]);
string sql = "select id,navigation_Name from navigation_Name where navigation_id = "+i.ToString();
DataTable dt = db.reDt(sql);
var rep=this.findcontrol("head_"+i.tostring()) as repeter;
rep.DataSource = dt;
rep.DataBind();
}
}
1.去看看三层架构(要学会分层~)
这个是主要的~学学ORM框架,如EF~
这个是也很重要。好了,说说怎么简化,1.减少相同的代码~不要复制
index1~5int id = string.IsNullOrEmpty(Request.QueryString["id"]) ? 0 : int.Parse(Request.QueryString["id"]);
都是一样的 可以提成参数
Index(int id)//奇怪的是你没有把Id传给sqlsql语句方面的优化
select id,navigation_Name from navigation_Name where navigation_id = 1
改成
DataTable dt = select id,navigation_Name from navigation_Name where navigation_id in(1,2,3,4,5);
变成一整个dt 减少对数据库的查询,然后再分割dt
index1(DataTable dt,int Id)
{
var view = dt.DefaultView.RowFilter = "id=1";
head_one.DataSource = view;
head_one.DataBind();
}index1(DataTable dt,int Id)
{
dt.DefaultView.RowFilter = "id=2";
.....
}........
<itemtemplate>
<li><span><a href="<%# Eval("Url").ToString()%><%# Eval("Id").ToString()%><%=webset.IsStatic %>"><%#Eval("Title") %></a></span></li>
</itemtemplate>
</cc1:WebRepeater>
public void head_index1()
{
string sql = "select id,navigation_Name,navigation_id from navigation_Name";
DataTable dt = db.reDt(sql);
HtmlTable htModel = new HtmlTable();
HtmlTableRow row = new HtmlTableRow();
HtmlTableCell cell = new HtmlTableCell();
for (int i = 0; i < length; i++)
{
Repeater head = new Repeater();
head.ID ="head_" i.ToString();
head.DataSource=dt.Select("navigation_id ="+i.ToString());
head.DataBind();
cell.Controls.Add(head);
row.Cells.Add(cell);
}
this.Panel1.Controls.Add(htModel);
}
1楼的太麻烦了,,我这个你应该容易理解,只需在界面上添加一个panel控件就可以了,就十来行代码
少了添加行的代码htModel.Rows.Add(row);
然后就是
public void head_index_one()
{ string sql = "select id,navigation from navigation where id = 1";
DataTable dt = db.reDt(sql);
head_five.DataSource = dt;
head_five.DataBind();
}
public void head_index_two()
..........
这些方法可以写成一个.
where = "+id
id 通过网页循环获取.
html脚本直接一个循环就可以简化很多代码.
思路不清晰.也没有什么好的思路.不知道你们做导航栏的时候是怎么做的?
当你一个页面有上10个以上Repeater的时候,你就不会觉得麻烦了,拓展Repeater,一劳永逸