摘要: 这两天,从微软官方网站的订阅站点下载,并把Microsoft Visual Studio 11 Developer Preview 升级为Visual Studio 11 Beta Ultimate版,以及把SQL Server 2008 R2升级为SQL Server 2012。意味着今后的开发是使用这工具和数据库了。以下内容于2012-03-23 20:46添加:What's New in ASP.NET 4.5 and Visual Studio 11 BetaWhat's New in SQL Server 2012阅读全文
posted @ 2012-03-23 14:19 Insus.NET 阅读(361) 评论(2) 编辑

问题来自论坛:http://topic.csdn.net/u/20120515/08/d429714e-523b-4dd1-ad9a-c107bc2fc11b.html

 

下面是Insus.NET试作演示:

 

 

演示源程代码:

.NET Framework 4.5 + C# + asp.net:
http://download.cnblogs.com/insus/ASPDOTNET/LoadUserControl.zip

 

posted @ 2012-05-15 16:17 Insus.NET 阅读(78) 评论(1) 编辑

老师布置的另外一道题是将字符串"a;b;d;z;y;u"切割成阵列并排序列出。老师出这题也许是让Insus.NET掌握或复习Array.Sort()函数,不管怎样,先按自己的想法实现,然后是等老师的意见。

 protected void Page_Load(object sender, EventArgs e)
    {
        string s = "a;b;d;z;y;u";
        string[] sa = s.Split(';');
        Array.Sort(sa); //排序
        for (int i = 0; i < sa.Length; i++)
        {
            Response.Write(sa[i].ToString() + "<br />");
        }
    }

 

 执行结果:

 

posted @ 2012-04-30 08:58 Insus.NET 阅读(138) 评论(0) 编辑

老师布置给Insus.NET第四道题目。一开始时,是使用下面的方法解答:

 protected void Page_Load(object sender, EventArgs e)
    {
        Response.Write(string.Format("数字1~10总和等于{0}。", Sum(110).ToString()));
    }

    private int Sum(int min, int max)
    {
        int s = 0;
        for (int i = min; i <= max; i++)
        {
            s += i;
        }
        return s;
    }

 

执行结果:

 

上面的方法,Insus.NET觉得不理想,故产生如下另外一个方法,重构了上面的Sum的函数:

    private int Sum(int min, int max)
    {
        return (max + 1) * max / 2;
    }

 

 

posted @ 2012-04-29 22:57 Insus.NET 阅读(188) 评论(1) 编辑

这是老师布置Insus.NET的第三道题目。以下是Insus.NET的答案,仅供参考:

 protected void Page_Load(object sender, EventArgs e)
    {
        //指定目标文件夹
        string directory = @"C:\Windows\Microsoft.NET\Framework\v3.5";

        IterationFile(directory);
    }

    private void IterationFile(string path)
    {
        DirectoryInfo di = new DirectoryInfo(path);
        
        //输出当前目录。
        Response.Write(di.ToString() + "<br />");
        //取得当前目录中所有文件
        FileInfo[] fiArray = di.GetFiles();

        //循环每一个文件
        for (int i = 0; i < fiArray.Length; i++)
        {
            Response.Write(fiArray[i].ToString() + "<br/>");
        }

        //每个目录结束,写一空行。
        Response.Write("----------------------------------------------------------------------------<br/>");
        //取得当前目录中所有子目录
        DirectoryInfo[] diArray = di.GetDirectories();

        //循环每一个目录
        for (int j = 0; j < diArray.Length; j++)
        {            
            IterationFile(diArray[j].FullName);
        }
    }

 

posted @ 2012-04-29 22:34 Insus.NET 阅读(174) 评论(0) 编辑

老师布置Insus.NET做的第二道题,题目如标题。

感兴趣的网友也可以练习练习。现在Insus.NET的作答如下,但老师还没有看,因此答案是否正确或是最好的,还不能确定,只是供参考。

 int max = (int)Math.Sqrt(150) + 1;

        for (int i = 1; i <= max; i++)
        {
            int j = i * i;
            Response.Write(i + " × " + i + " = " + j + "<br />");
        }

 

 结果:

 

posted @ 2012-04-29 22:08 Insus.NET 阅读(110) 评论(0) 编辑

老师布置作业给Insus.NET做,题目如标题。

感兴趣的网友也可以练习练习。现在Insus.NET的作答如下,但老师还没有看,因此答案是否正确或是最好的,还不能确定,只是供参考。

第一次以最快的方法来实现:

        for (int i = 1; i <= 20; i++)
        {
            int j = i * i;
            if (j >= 50)
                Response.Write(i + " × " + i + " = " + j + "<br />");
        }

 

得到结果如下:

 

在上面完成之后,Insus.NET马上想起,老师一定不会出这样简单的问题的。会不会老师要Insus.NET实现,积小于50的两个数字相乘的不必循环呢,减轻性能,因此马上修改刚才完成的程序:

首先求出50的平方根数为多少,得到的数为Double的数据类型,也就是说有可以是小数出现,把它转换为Integer:

int min = (int)Math.Sqrt(50);

 

这样,我们就可以知道是从哪一个Integer开始进行循环。但是某一天,不再是计算积为50,而是改为积64的话,它的平方根为8。如果以8的平方刚好是64,而题目是要大于64的,因此正确是从9开始。故还是下面的判断:

if (Math.Pow(min, 2) < 50)
    min += 1;

 

最终Insus.NET的答案如下:

 for (int i = min; i <= 20; i++)
        {
            int j = i * i;
            Response.Write(i + " × " + i + " = " + j + "<br />");
        }

 

结果还是同第一次的结果一样。

posted @ 2012-04-29 21:38 Insus.NET 阅读(100) 评论(0) 编辑

比如一个字符串"a,b,a,c,b,b,d",现在我们要统计每个字符串出现次数。解决这个问题,我们可以使用泛型集合 Dictionary(TKey,TValue)。它有一个key值用来存储字符串和一个value值,用来存储字符串出现的次数。

实现第一步,需要把字符串分割为一个array,需要使用到的函数Split():

string[] arr = s.Split (',');

 

第二步,用Dictionary(TKey,TValue)实例化。

Dictionary<stringint> Statistics = new Dictionary<stringint>();

 

第三步,统计:

 foreach (string w in arr)
        {
            if (Statistics.ContainsKey(w))
            {
                Statistics[w] += 1;
            }
            else
            {
                Statistics[w] = 1;
            }
        }

 

写完以上代码算是大功告成。

但Insus.NET还是要把统计的结果显示出来:

.aspx:

View Code
 <asp:Repeater ID="Repeater1" runat="server">
            <HeaderTemplate>
                <table border="1" cellpadding="1" cellspacing="0">
                    <tr>
                        <td>字符 </td>
                        <td>次数 </td>
                    </tr>
            </HeaderTemplate>
            <ItemTemplate>
                <tr>
                    <td>
                        <%Eval("key"%>
                    </td>
                    <td>
                        <%Eval("value"%>
                    </td>
                </tr>
            </ItemTemplate>
            <FooterTemplate>
                </table>
            </FooterTemplate>
        </asp:Repeater>

 

.aspx.cs:

View Code
 protected void Page_Load(object sender, EventArgs e)
    {
        this.Repeater1.DataSource = Statistics;
        this.Repeater1.DataBind();
    }

 

结果:

 

 

如果你想看看MS SQL Server版本: http://www.cnblogs.com/insus/archive/2012/02/23/2364580.html

 

posted @ 2012-04-29 10:36 Insus.NET 阅读(141) 评论(2) 编辑

本演示是让你知道如何多个值绑定至ListBox显示为选中。ListBox在default情况之下,SelectionMode为Single,因此为了多选,而需要设置此属性为Multiple。在实现之前,可以先看到Insus.NET所实现最终效果,gif动画,无声音:

 

 

 .aspx:

 <asp:TextBox ID="TextBox1" runat="server" Width="300"></asp:TextBox>
        <br />
        <asp:Button ID="Button1" runat="server" Text="Binding" OnClick="Button1_Click" />
        <br />
        <br />
        <asp:ListBox ID="ListBox1" runat="server" Height="100" SelectionMode="Multiple" ></asp:ListBox>

 

.aspx.cs中,首先是为ListBox准备数据,然后对ListBox控件进行数据绑定:

View Code
 protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Data_Binding();
        }

    }

    private void Data_Binding()
    {
        this.ListBox1.DataSource = Site();
        this.ListBox1.DataTextField = "key";
        this.ListBox1.DataValueField = "value";
        this.ListBox1.DataBind();
    }

    private Dictionary<stringstring> Site()
    {
        Dictionary<stringstring> site = new Dictionary<stringstring>();
        site.Add("Insus.NET cnblogs""http://insus.cnblogs.com");
        site.Add("Microsoft""http://www.microsoft.com");
        site.Add("Google""http://www.google.com");
        site.Add("Yahoo""http://www.yahoo.com.cn");
        site.Add("Ifeng""http://www.ifeng.com");
        site.Add("sina""http://www.sina.com.cn");
        site.Add("163""http://www.163.com");
        site.Add("QQ""http://www.qq.com");
        return site;
    }

 

为了让TextBox的字符串以";"分割为多个值,引用了命名空间

using System.Collections;

 

接下来,是写button的click事件,代码相当简单,Insus.NET在此不作过多注释:

View Code
protected void Button1_Click(object sender, EventArgs e)
    {
        string[] s = this.TextBox1.Text.Split(';');
        
        foreach (ListItem li in this.ListBox1.Items)
        {                     
            li.Selected = ((IList)s).Contains(li.Text) ? true : false;           
        }
    }

 

 

 

posted @ 2012-04-26 22:21 Insus.NET 阅读(189) 评论(0) 编辑

专案需要,一个TextBox要存储时间值。由于asp.net的Validation的验证工具的asp:CompareValidator只能验到日期。验证日期可以参考:http://www.cnblogs.com/insus/archive/2012/03/24/2415171.html

如何判断用户在TextBox输入的字符串就是一个有效的时间呢? Insus.NET解决方法并没有使用正则表达式,也可以实现到相同验证效果,没有警告提示,说明输入的字符串是一个有效的时间字符串:

 

 

 .aspx,放置一个TextBox, 写OnTextChanged事件,还要设置AutoPostack=“true”属性。

<asp:TextBox ID="TextBoxSendTime" runat="server" CssClass="textbox" Width="70" AutoPostBack="true" OnTextChanged="TextBoxSendTime_TextChanged"></asp:TextBox>

 

 .aspx.cs:

protected void TextBoxSendTime_TextChanged(object sender, EventArgs e)
    {
        var tb = sender as TextBox;
        //ConverData类别,可以参考:http://www.cnblogs.com/insus/articles/1424094.html
        if (ConvertData.ToDateTime(DateTime.Today.ToString("yyyy-MM-dd") + " " + tb.Text.Trim()) == null)
        {
            //以下类别,参考:http://www.cnblogs.com/insus/articles/1341703.html
            InsusJsUtility objInsusJsUtility = new InsusJsUtility();
            objInsusJsUtility.JsAlert("输入字符串不是有效时间。");
            return;
        }
    }

 

 

posted @ 2012-04-26 17:54 Insus.NET 阅读(161) 评论(2) 编辑

Vertical Line显示效果:

 

 使用CSS:

border-right: #a5acb5 1px solid; 

 

详细的html code(Highlight部分): 

 

 

posted @ 2012-04-26 08:47 Insus.NET 阅读(134) 评论(0) 编辑