.Net怎么在HTML页面嵌入代码以进行判断?

来源:百度知道 编辑:UC知道 时间:2024/05/22 08:38:45
比如Repeater中判断一个绑定的字段如果是0的话就显示"不存在"
如果是1就显示"存在"
以前ASP可以直接嵌入if判断
.net 怎么弄啊

如果是GridView,那么在其RowDataBound事件中写代码即可
例如:
protected void gvEmployeeBase_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType != DataControlRowType.Header && e.Row.RowType != DataControlRowType.Footer)
{
if (e.Row.RowIndex >= 0)
{
if(e.Row.Cells[7].Text=="0")
{
e.Row.Cells[7].Text="不存在";
}
if(e.Row.Cells[7].Text=="1")
{
e.Row.Cells[7].Text="存在";
}
//添加自定义属性,当鼠标移过来时设置该行的背景色为"#EBEBED",并保存原背景色

e.Row.Attributes.Add("onmouseover", "currentcolor=this.style.backgroundColor;this.style.backgroundColor='#EBEBED'");
//添加自定义属性,当鼠标移走时还原该行的背景色
e.Row.Attributes.A