小编Pet*_*ter的帖子

JQuery - 添加onclick以动态生成img标记

我使用以下代码动态创建多个图像:

function refresh_gallery(galleryidentifier, albumid) {
    $.ajax({ type: "POST", url: "/Photos/Thumbnails/" + albumid + "/", data: {}, success: function(msg) {
        try {
            var fotos = eval(msg); $(galleryidentifier).empty(); if (fotos.length == 0) { $(galleryidentifier).html("Press "Add files..." and select files to upload!"); return true; }
            for (var f in fotos) {
                //this image needs the onclick eventhandler
                $(document.createElement("img")).attr({ src: '/images/delete.gif', title: 'Delete ' + fotos[f].Title }).addClass("icon_delete").appendTo(galleryidentifier); ;
                $(document.createElement("img")).attr({ src: fotos[f].ThumbnailPath, title: fotos[f].Title }).addClass("thumbnail").appendTo(galleryidentifier);
            }
            var del_div = $(document.createElement("div")).css({ "padding": "4px" }).appendTo(galleryidentifier);
            var delete_span …
Run Code Online (Sandbox Code Playgroud)

jquery

9
推荐指数
3
解决办法
7万
查看次数

Visual Studio 2010和TFS 2008:构建单元测试项目

我们目前正在将VS2010用于测试驱动器,到目前为止,我们对它如何不与我们现有的Team Foundation Server 2008合作感到有些困惑.我们仍然拥有.NET 3.5上的所有项目以及我们现在正在构建解决方案它包含一个单元测试项目(自动在.NET 4.0中构建),TFS不会构建它.

.NET 4.0框架安装在TFS 2008上.

我们收到的错误是:

[Any CPU/Release] c:\WINDOWS\Microsoft.NET\Framework\v3.5\Microsoft.Common.targets(0,0): warning MSB3245: Could not resolve this reference. Could not locate the assembly "Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.

作为临时解决方法,我们现在被迫删除所有测试项目,以便构建我们的解决方案.

unit-testing tfs2008 .net-4.0 visual-studio-2010

9
推荐指数
1
解决办法
4268
查看次数

实体框架 - 分层设计 - 在哪里放置连接字符串?

我正在使用一个分层架构,将实体框架作为我的数据层,顶部有一堆存储库,其中包含Linq-To-Entities查询.数据层是一个项目,旁边是我有一个服务层和接口,这是一个网站.

我希望我的网站负责为我的实体模型指定连接字符串.我该怎么做呢?

我使用单例方法到达我的实体存储库,该存储库位于数据层内.

谢谢

c# entity-framework data-access-layer n-tier-architecture

8
推荐指数
1
解决办法
8793
查看次数

从Office 2003执行.NET 3.0代码

我使用.NET 3.0框架在C#中创建了一个DLL.

下面是我的DLL的代码

namespace CompanyName.Net
{
    [Guid("F7075E8D-A6BD-4590-A3B5-7728C94E372F")]
    [ClassInterface(ClassInterfaceType.AutoDual)]
    [ProgId("CompanyName.Net.Webrequest")]
    public class WebRequest
    {
        public string Result { get; private set; }
        public string Url { get; set; }
        public string StatusDescription { get; private set; }
        public HttpStatusCode StatusCode { get; private set; }

        public WebRequest()
        {
            //explicit constructor
        }    

        public string GetResponse(string url)
        {
            System.Net.WebRequest webreq = System.Net.WebRequest.Create(url);
            HttpWebResponse response = (HttpWebResponse) webreq.GetResponse();
            // Store the status.
            StatusDescription = response.StatusDescription;
            StatusCode = response.StatusCode;
            // Get the stream containing content …
Run Code Online (Sandbox Code Playgroud)

.net c# dll vba access-vba

8
推荐指数
1
解决办法
1385
查看次数

(276/304)*304关闭十进制舍入

如果您在编译器中放入以下代码,结果有点奇怪:

decimal x = (276/304)*304;
double y = (276/304)*304;

Console.WriteLine("decimal x = " + x);
Console.WriteLine("double y = " + y);
Run Code Online (Sandbox Code Playgroud)

结果:

十进制x = 275.99999999999999999999999

双y = 276.0

谁可以给我解释一下这个?我不明白这是怎么回事.

.net c# floating-point types

7
推荐指数
1
解决办法
527
查看次数

如何将变量值放在资源文件的值内

我一直在使用资源文件一段时间,我想知道是否有一些漂亮的方式我不知道还没有将变量放在资源值中.

一个简单的例子:

你已经购买了#amountOfBooksBought书籍.

我目前的工作方式是声明两个资源值(对于2个标签):

BoughtBooksAmountPreTextLabel.Text:"你买了"
BoughtBooksAmountPostTextLabel.Text:"书籍".

在带有此文本的两个标签之间,会有一个名为BoughtBooksAmountValueLabel的标签,其中包含购买的书籍数量.

是否有一个更优雅的解决方案或这只是它?

.net resource-files

6
推荐指数
1
解决办法
3740
查看次数

在ASPX中为RadioButtonList将ListItem值设置为常量

我必须在这里做错事,但我找不到一个简单的方法让它工作.

想象一下以下代码:

<asp:RadioButtonList ID="MyRadioButtonList" runat="server">
    <asp:ListItem Value="<%= CompanyName.SystemName.Constants.PaymentFrequency.FREQUENT.ToString() %>" Text="Yes" Selected="True"></asp:ListItem>
    <asp:ListItem Value="<%= CompanyName.SystemName.Constants.PaymentFrequency.ONCE.ToString() %>" Text="No, Just do this once"></asp:ListItem>
</asp:RadioButtonList>
Run Code Online (Sandbox Code Playgroud)

但它不会在呈现页面之前编译语句.所以,如果我得到这个单选按钮列表中选择的值就包含有类似的"<%= COMPAN ...%>",而不是什么我的常量定义.

这个的正确语法是什么?

asp.net

6
推荐指数
1
解决办法
1763
查看次数

我可以在visual studio 2012 t-sql编辑器中定义#regions吗?

我想知道是否有一个扩展允许我在编辑用户定义的函数或普通的t-sql查询时定义visual studio 2012编辑器中的区域.

我尝试了以下但是它似乎没有做太多:

-- #region This is a region with t-sql code
   ...
-- #endregion
Run Code Online (Sandbox Code Playgroud)

sql-server editor visual-studio-2012

6
推荐指数
1
解决办法
3211
查看次数

c#在自定义属性中执行代码

可能重复:
为什么我的.NET属性不执行操作?

嗨,

这可能听起来像一个非常愚蠢的问题,我不知道这里有什么可能,因为网上的所有"自定义属性"教程几乎都是相同的,并且它们没有解决我想要做的事情.我已经看到了一些代码在代码中写入属性类的代码,例如:使用ASP.NET MVC Action Filters进行日志记录,我想知道这个代码是如何执行的.

如果我有以下代码:

public class Test
{
    [RestrictedAttribute("RegisteredMember")]
    public void DoSomething()
    {
        //this code can only be executed if the logged-in user
        //is a member of the RegisteredMember group
    }
}
Run Code Online (Sandbox Code Playgroud)

然后自定义Attribute RestrictedAttribute将是这样的:

[AttributeUsage(AttributeTargets.Method)]
public class RestrictedAttribute : System.Attribute 
{
    /// <summary>
    /// Make this code restricted to users with a required role
    /// </summary>
    /// <param name="requiredRole">The role required to execute this method</param>
    public RestrictedAttribute(string requiredRole)
    {
        //validate if member is in …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-mvc attributes runtime

5
推荐指数
1
解决办法
3722
查看次数

从Linq To Entities可视化生成的SQL

我正在寻找一种方法来查看我的L2E代码为调试目的生成的sql是什么.我已经阅读了Scott G.在Linq2SQL的可视化工具上博客文章,但我无法让它适用于L2E.

你知道从L2E可视化生成的SQL的某种方法吗?

我使用的是Visual Studio 2008 SP1 Professional.

linq-to-entities visual-studio

4
推荐指数
1
解决办法
1722
查看次数