最近和技术主管一起开发项目,做完了我来维护,可当我维护到他的功能时,我有点郁闷,他的代码是这样写!前台除了头部样式和页脚样式,中间就一个run at server 的DIV 然后如下图的代码,对于做了一年多开发的我,没怎么看过W3C的标准,但是这样的代码确实让我觉得有眼花,不好维护。而且对方是个有10年工作经验的了,是我们开发主管。但我又说不出这样开发的各种弊端,肯请各位大神点评下,同时小弟自己也学习一下。也希望各位大神不吝赐教各种开发中应该注意的一些规范,对于各大神的贡献,小弟将感激不尽,谢谢。
解决方案 »
- 导出Excel标题成乱码,打开时提示格式与类型不符,但是打开后没问题
- VS自带数据库,没有安装SQL Server2005的时候出现问题
- 急急急,asp.net中如何使GridView进行自动排序,谢谢
- grideview导出excel
- 一道难题(sql触发器),请高手解答一下,挺有难度的
- 两个验证控件验证同一个输入框的错误提示信息的显示位置问题
- 我想把网站的新闻生成静态的,在新闻页面想实现页首和页脚的包含,因为怕以后有更改,有要把新闻重新生成!大家都是怎么多的
- this.newsgrid.Items[i].Cells[7].ForeColor=
- 下载文件时有什么办法可以不直接打开文件而是弹出下载对话框?
- acptvb兄台及各位大虾:怎样利用dropdownlist的参数进行选择问题
- 查询sql语句中的列信息
- 怎样将一个excel文件导出成xml文件
另外啊,把HTML代码嵌到CS代码里,不好吧,修改是不是还要重新编译上传啊
不过,有时也根据需要适当的在CS代码里有一些html的东西!看情况,呵呵!
DataTable dt = new BLL.pd_ProductList().GetList(PagingNewsInfo.PageSize, pageIndex, " IsDelete=0 and Flag=0 and Trade_ID=" + tid + " and TradeCategory_ID="+id, " ID desc", out total).Tables[0];
Model.pd_Trade tm = new BLL.pd_Trade().GetModel(int.Parse(tid));
string strContent = "";
string strShowContent = "";
for (int i = 0; i < 5; i++)
{
int tmpid = i + 1;
if (i < dt.Rows.Count)
{ strContent += "<div value='" + i.ToString() + "' class='sysmex_d_0" + tmpid.ToString() + "'><a href='ProductDetail.aspx?id=" + dt.Rows[i]["ID"].ToString() + "&tname=" + tm.TradeName + "'><img src='" + dt.Rows[i]["ImagePath"].ToString() + "'/></a></div>";
string tmpContent = dt.Rows[i]["Content"].ToString();
if (!string.IsNullOrEmpty(tmpContent))
{
if (tmpContent.Length > 300) tmpContent = tmpContent.Substring(0, 300) + "...<br/><div class='see'style='text-align:right'><a href='ProductDetail.aspx?id=" + dt.Rows[i]["ID"].ToString() + "&tname="+tm.TradeName+"'><b>MORE</b></a></div>";
else tmpContent = tmpContent + "...<br/><div class='see'style='text-align:right' ><a href='ProductDetail.aspx?id=" + dt.Rows[i]["ID"].ToString() + "&tname=" + tm.TradeName + "'><b>MORE</b></a></div>";
strShowContent += "<div class='sysmexdetail' style='display:none'>"
+ "<div class='sysmex_title'><b>" + dt.Rows[i]["ProductName"].ToString() + "</b></div>"
+ "<div class='sysmexcon'>" + tmpContent + "</div></div>";
}
else
{
strShowContent += "<div class='sysmexdetail' style='display:none'>"
+ "<div class='sysmex_title'></div>"
+ "<div class='sysmexcon'></div></div>";
}
}
else
{
strContent += "<div value='" + i.ToString() + "' class='sysmex_d_0" + tmpid.ToString() + "'></div>";
strShowContent += "<div class='sysmexdetail' style='display:none'>"
+ "<div class='sysmex_title'></div>"
+ "<div class='sysmexcon'></div></div>";
}
} divContent.InnerHtml = strContent;
divContent.InnerHtml += "<div value='5' class='sysmex_06' ><a href='Sysmex.aspx?id=" + tm.ID.ToString() + "'><img src='" + tm.ImagePath + "'></a></div>";
if (!string.IsNullOrEmpty(tm.Content))
{
strShowContent += "<div class='sysmexdetail' >"
+ "<div class='sysmex_title'><b>" + tm.TradeName + "</b></div>"
+ "<div class='sysmexcon'>" + tm.Content + "</div></div>";
}
else
{
strShowContent += "<div class='sysmexdetail' style='display:none'>"
+ "<div class='sysmex_title'></div>"
+ "<div class='sysmexcon'></div></div>";
}
divShowContent.InnerHtml = strShowContent;
我也这么搞过。
没用过asp 只听说代码和前台是混一起在
没用过asp 只听说代码和前台是混一起在
我基本没有在后台写过html代码返回,后台的都是数据绑定和一些操作。因为asp.net本身写法就是一个前后台分离的 protected void Bind()
{
int totalCount = 0;
if (txtId.Text.Trim() == "")
{
return;
}
rptProject.DataSource = BLL.PagingLogic.ExecutePage("(SELECT p.*,c.CompanyCode FROM dbo.us_CompanyProject p LEFT JOIN dbo.us_CompanyList c ON c.ID=p.CompanyID) t1", "*", "Orderby", GetWhere(), PagingDataInfo.CurrentPageIndex, 10, ref totalCount);
rptProject.DataBind();
PagingDataInfo.RecordCount = totalCount;
rptProjectDetail.DataSource = null;
rptProjectDetail.DataBind();
}
protected string GetWhere()
{
string where = " IsDelete=0 ";
if (txtId.Text.Trim() != "")
{
if (StringPlus.SqlFilter(txtId.Text))
return where;
where += " and CompanyCode ='" + txtId.Text.Trim() + "'";
}
return where;
}
protected void PagingDataInfo_Click(object sender, EventArgs e)
{
Bind();
} protected void btnSelect_Click(object sender, EventArgs e)
{
PagingDataInfo.CurrentPageIndex = 1;
Bind();
} protected static string ProjectName = "";
protected static int Count = 0;
protected void rptProject_Command(object source, RepeaterCommandEventArgs e)
{
if (e.CommandName == "getproject")
{
if (e.CommandArgument != null && e.CommandArgument.ToString() != "")
{ string[] value = e.CommandArgument.ToString().Split('|');
List<Model.us_CompanyProjectList> companyProjectLists =
new BLL.us_CompanyProjectList().GetModelList(" Project_ID=" + value[0]);
Count = companyProjectLists.Count;
rptProjectDetail.DataSource = companyProjectLists;
rptProjectDetail.DataBind();
new BLL.sys_TrafficStatistics().UpdateViewRecord(TableName.pd_ProductList, Convert.ToInt32(value[0]));
if (value.Length >= 3)
{
ProjectName = value[2];
MessageBox.ResponseScript(this, "setClass('" + value[1] + "')");
} }
}
}
}
这个是对的。还有如果为了逻辑清晰的话,我还喜欢使用string.format
但是这个页面只是因为一些样式上的布局而这样用的,如果单纯是样式的问题我觉得怎么说都还是在前台通过CSS或JS来实现好,这样方便程序员维护,也方便美工啊!
嗯!是的。string 拼接,每次都是重新赋值!而不是直接在后面加上。
在线改用<% foreach()%>的方法在前台写html了,
个人觉得这些写法都没啥大的弊端,哪个喜欢用哪个写吧
就算那不考虑维护的问题,最起码拼接也不该那样写
应该用StringBuiler...然后AppendFormat...
如果不能把他干掉,那就走人吧...