ASP.NET 常用功能收藏

简介: 1、两个Repeater嵌套实现动态菜单今天在实现一个增强web项目可扩展性的一个功能,把以前的静态菜单改成了动态的扩展、可维护的菜单页面代码 ...

1、两个Repeater嵌套实现动态菜单

今天在实现一个增强web项目可扩展性的一个功能,把以前的静态菜单改成了动态的扩展、可维护的菜单

页面代码

<asp:Repeater ID="Repeater1" runat="server"  onitemdatabound="Repeater1_ItemDataBound">
        <ItemTemplate>
         <h1 class="type"><a href="javascript:void(0)"><%# DataBinder.Eval(Container.DataItem, "MT_name")%></a></h1>
            <asp:Repeater ID="Repeater2" runat="server">
            <HeaderTemplate> 
            <div class="content">
            <table width="100%" border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td><img src="images/menu_topline.gif" width="182" height="5" /></td>
            </tr>
          </table>
        <ul class="MM">
            </HeaderTemplate>
            <ItemTemplate>
             <li><a href="<%# DataBinder.Eval(Container.DataItem, "MI_page")%>" target="main"><%# DataBinder.Eval(Container.DataItem, "MI_name")%></a></li>
            </ItemTemplate> 
            <FooterTemplate>
            </ul></div>
            </FooterTemplate>
            </asp:Repeater>
        </ItemTemplate>
</asp:Repeater>


 服务器端代码

public partial class left : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string sql = "select MT_ID,MT_name from ModuleTopInfo";
                SqlDbHelper db = new SqlDbHelper();//SqlHelper类你懂得
                Repeater1.DataSource =db.ExecuteDataTable(sql);
                Repeater1.DataBind();
            }
        }

        protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                string id = ((DataRowView)e.Item.DataItem).Row["MT_ID"].ToString();
                Repeater rpt = (Repeater)e.Item.FindControl("Repeater2");
                string sql = "select MI_ID,MI_page,MI_name from ModuleInfo where MT_ID=@id";
                SqlParameter[] parameters = new SqlParameter[] {
                    new SqlParameter("@id",id)
                };
                SqlDbHelper db = new SqlDbHelper();
                DataTable dt = new DataTable();
                dt = db.ExecuteDataTable(sql,CommandType.Text,parameters);
                if (rpt != null)
                {
                    rpt.DataSource = dt;
                    rpt.DataBind();
                }
            }
        }


 实现效果截图


2、通过format输出带{}的字符


string s = string.Format("abc{{{0}}}{{{1}}}", "9999","123");
 Response.Write(s);

//输出

abc{9999}{123}


3、弹出框样式

http://www.cnblogs.com/zengxiangzhan/archive/2011/08/27/2155335.html


4、LINQ To XML增删改查

http://www.cnblogs.com/mingmingruyuedlut/archive/2011/01/27/1946239.html


5、C# WinForm下DataGridView绘制背景图

http://archive.cnblogs.com/a/2201983/


6、数据控件行选择事件

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            //当鼠标在某行,更改背景色
            e.Row.Attributes.Add("onmouseover", "color=this.style.backgroundColor;this.style.backgroundColor='#F9D79C'");
            //当鼠标离开,还原背景色
            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=color");

            //鼠标变小手   ondblclick双击onClick单击
            e.Row.Attributes["style"] = "Cursor:hand";
            e.Row.Attributes.Add("onClick", "this");
            string nodenumber = GridView1.DataKeys[e.Row.RowIndex].Value.ToString();
            e.Row.Attributes.Add("onClick", "window.open('manage/AddNodeB.aspx?nodenumber=" + nodenumber + "');window.parent.top.opener = null;window.open('','_self');parent.top.window.close()");
        }
    }

数据库连接字符串:http://www.connectionstrings.com/


var zNodes =[{"name":"所用","id":"001","pid":"001",
 nodes:[{"name":"所用1","id":"0011","pid":"001111"}]},
 
{"name":"核计划","id":"002","pid":"002",
 nodes:[{"name":"核计划1","id":"0021","pid":"002"}]}],

---------------------------------------------------------------------
function showAllNode(thejson){
  var flag = false;// 当前元素是否是数组
  for(var e in thejson){

      alert("e:"+e);
      if(e=="parentNode")
            continue;
      for(var ex in thejson[e]){
             flag = true;
             break;
       }
      if(flag){
          showAllNode(thejson[e]);
       }else if(thejson[e]){
         alert(thejson[e]);

     }
   
   }
   if(!flag)
  {
      return;
  }
   
}



相关文章
|
4月前
|
存储 文字识别 C#
.NET开源免费、功能强大的 Windows 截图录屏神器
今天大姚给大家分享一款.NET开源免费(基于GPL3.0开源协议)、功能强大、简洁灵活的 Windows 截图、录屏、Gif动图制作神器:ShareX。
|
1月前
|
人工智能 开发框架 .NET
.NET技术的强大功能:.NET技术的基础特性、在现代开发中的应用、以及它如何助力未来的软件开发。
.NET技术是软件开发领域的核心支柱,以其强大功能、灵活性及安全性广受认可。本文分三部分解析:基础特性如多语言支持、统一运行时环境;现代应用如企业级与Web开发、移动应用、云服务及游戏开发;以及未来趋势如性能优化、容器化、AI集成等,展望.NET在不断变化的技术环境中持续发展与创新。
65 4
|
4月前
|
定位技术 API C#
.NET开源、功能强大、跨平台的图表库
.NET开源、功能强大、跨平台的图表库
|
1月前
|
开发框架 JavaScript 前端开发
提升生产力:8个.NET开源且功能强大的快速开发框架
提升生产力:8个.NET开源且功能强大的快速开发框架
|
1月前
|
Unix Linux C#
增强用户体验:2个功能强大的.NET控制台应用帮助库
增强用户体验:2个功能强大的.NET控制台应用帮助库
|
1月前
|
设计模式 前端开发 数据可视化
LiveCharts2:简单灵活交互式且功能强大的.NET图表库
LiveCharts2:简单灵活交互式且功能强大的.NET图表库
40 0
|
3月前
|
存储 编解码 算法
C#.NET逃逸时间算法生成分形图像的毕业设计完成!晒晒功能
该文介绍了一个使用C#.NET Visual Studio 2008开发的程序,包含错误修复的Julia、Mandelbrot和优化过的Newton三种算法,生成色彩丰富的分形图像。作者改进了原始算法的效率,将内层循环的画点操作移至外部,提升性能。程序提供五种图形模式,支持放大缩小及颜色更新,并允许用户自定义画布大小以调整精度。还具备保存为高质JPG的功能。附有四张示例图片展示生成的分形效果。
|
2月前
|
C# 开发者 Windows
4款.NET开源、功能强大的Windows桌面工具箱
4款.NET开源、功能强大的Windows桌面工具箱
|
2月前
|
C# C++
一款.NET开源、功能强大、跨平台的绘图库 - OxyPlot
一款.NET开源、功能强大、跨平台的绘图库 - OxyPlot
|
2月前
|
人工智能 C#
Jvedio:.NET开源功能强大的本地视频管理神器
Jvedio:.NET开源功能强大的本地视频管理神器
108 0