小编w00*_*977的帖子

将GridView列值传递给Javascript函数 - OnClientClick

我有这样的网格视图:

<asp:SqlDataSource ID="SqlPersistentOffenders" runat="server"></asp:SqlDataSource>
    <asp:GridView ID="GVPersistentOffenders" runat="server" DataSourceID="SqlPersistentOffenders" AllowPaging="true" AutoGenerateColumns="false">
    <Columns>
        <asp:TemplateField HeaderText="PersonID" Visible="false">
            <ItemTemplate>
                 <asp:Label ID="LabCreUser" runat="server" Text='<%# Bind("creUser")%>'></asp:Label>                       
            </ItemTemplate>
        </asp:TemplateField>
         <asp:TemplateField>
            <ItemTemplate>
                <asp:Button ID="ButtonSendEmail" runat="server" CommandName="SendEmail" CommandArgument="<%# CType(Container,GridViewRow).RowIndex %>" Text="Send Email" OnClientClick="GetEmailAddress()"/>                     
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>
Run Code Online (Sandbox Code Playgroud)

JavaScript看起来像这样:

<script type="text/javascript">
        function GetEmailAddress(creuser) {
           //Do something
}
</script>
Run Code Online (Sandbox Code Playgroud)

如何将LabCreUser中的值传递给选择的行到Javasript函数?

我看过这里:在onclientclick中将变量传递给javascript以及其他一些问题.我没有尝试过任何工作.

javascript vb.net asp.net

2
推荐指数
1
解决办法
8894
查看次数

枚举的好处

我正在努力理解 IEnumerable 的好处。我知道 Enumerables 允许延迟执行。

请参阅此处的示例:https : //msdn.microsoft.com/en-us/library/system.collections.ienumerable(v=vs.110).aspx。在此示例中,该数组已填充到主类中,然后注入到 IEnumerable 类中。因此,这似乎消除了推迟执行的优势。我在这里缺少什么?

c# ienumerable ienumerator

2
推荐指数
1
解决办法
1151
查看次数

存储过程:数据库中已经有一个名为“#columntable”的对象

请看下面的代码:

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE Test
AS
BEGIN
    begin
    select * into #dbreviews from dbreviews
    end

    drop table #dbreviews

    begin
    select * into #dbreviews from dbreviews
    end

END
GO
Run Code Online (Sandbox Code Playgroud)

我得到的错误是:

'#dbreviews'数据库中已经有一个命名的对象。

像这样的问题:数据库中已经有一个名为“#columntable”的对象告诉我这应该是可能的。

sql t-sql sql-server

2
推荐指数
1
解决办法
5184
查看次数

用一行代码填充Enumerable.ToList

请看下面的人员类:

public class Person
    {
        int _id { get; set; }
        string _name { get; set; }

        public Person (int id, string name)
        {
            _id = id;
            _name = name;
        }

        public Person()
        {
        }

        public IEnumerable<Person> GetPeople()
        {
            _id = 1;
            _name = "James";
            yield return this;

            _id = 2;
            _name = "Michael";
            yield return this;

            _id = 3;
            _name = "Sarah";
            yield return this;
        }
    }
Run Code Online (Sandbox Code Playgroud)

以及下面的客户代码:

Person p1 = new Person();
IEnumerable<Person> personEnumerable = p1.GetPeople();
List<Person> personList …
Run Code Online (Sandbox Code Playgroud)

.net c# ienumerable

2
推荐指数
1
解决办法
71
查看次数

如何确保在每个循环上创建新Person?

请参阅下面的代码,这是我的单元测试的一部分:

mockPersonFactory.Setup(m => m.Create()).Returns(PersonFactory());

public IPerson PersonFactory()
{
    IPerson iPerson = new Person();
    return iPerson;
}
Run Code Online (Sandbox Code Playgroud)

PersonFactory应该多次调用(因为它包含在被测试代码的循环中).但是,不是Person每次在循环中创建新的,而是每次都重用同一个人对象.如何确保在每个循环上创建新Person?

c# nunit unit-testing moq

2
推荐指数
1
解决办法
76
查看次数

@Html.HiddenFor 在 HttpPost 中导致 null

请看下面的代码:

 @model NHibernate.AspNet.Identity.IdentityRole
@{
    ViewBag.Title = "Edit";
    Layout = "~/Areas/Administration/Views/Shared/_Layout.cshtml";
}

@using (Html.BeginForm())
{
    @Html.AntiForgeryToken()
    @Html.ValidationSummary(true)
    @Html.HiddenFor(model => model.Id)
    <div>
        Role name
    </div>
    <p>
        @Html.TextBoxFor(model => model.Name)
    </p>
    <input type="submit" value="Save" />
}
Run Code Online (Sandbox Code Playgroud)

和下面的代码:

[HttpPost]
        public ActionResult Edit(IdentityRole role)
        {
            Service.Update(role);
            TempData["Comment"] = "The record was updated";
            return RedirectToAction("Index");
        }
Run Code Online (Sandbox Code Playgroud)

Role.Id 在控制器中始终为空。Role.Description 包含正确的值。

角色不会更新,因为 Role.Id 为空。问题是什么?

c# nhibernate asp.net-mvc

2
推荐指数
1
解决办法
484
查看次数

FluentAssertions:字符串不包含ShouldBeEquivalentTo的定义

我正在尝试使用Nspec。我已按照以下说明进行操作:http : //nspec.org/

  1. 创建一个类库项目
  2. Nuget:安装软件包nspec
  3. Nuget:安装包FluentAssertions
  4. 创建一个类文件并粘贴以下代码:

using NSpec;
using FluentAssertions;

class my_first_spec : nspec
{
    string name;

    void before_each()
    {
        name = "NSpec";
    }

    void it_asserts_at_the_method_level()
    {
        name.ShouldBeEquivalentTo("NSpec");
    }

    void describe_nesting()
    {
        before = () => name += " Add Some Other Stuff";

        it["asserts in a method"] = () =>
        {
            name.ShouldBeEquivalentTo("NSpec Add Some Other Stuff");
        };

        context["more nesting"] = () =>
        {
            before = () => name += ", And Even More";

            it["also asserts in a lambda"] …
Run Code Online (Sandbox Code Playgroud)

c# fluent-assertions nspec

2
推荐指数
1
解决办法
2429
查看次数

通过示例了解六角形端口和适配器的概念

在谈论六角形架构时,我试图理解端口和适配器的含义。今晚我读了很多解释,但是我还没有找到代码示例。因此我将设计一个。我将端口理解为一个接口。例如:

public interface IPerson
{
   string GetName();
}
Run Code Online (Sandbox Code Playgroud)

适配器是实现接口的类:

public class Person : IPerson
{
  //Implementation of GetName here
}
Run Code Online (Sandbox Code Playgroud)

我理解四联适配器模式的概念。但是,我不明白这如何适合 DDD。

在 DDD 上下文中查看一个简单的代码示例确实对我有帮助。

c# domain-driven-design

2
推荐指数
1
解决办法
2820
查看次数

为什么 Visual Studio 2019 在“适用于 Android 的 Visual Studio 模拟器”中启动后不显示模拟器?

我最近在家中的电脑上卸载了 Visual Studio 2017 Community 版并安装了 Visual Studio 2019 Community 版。

由于此处描述的问题,我从未设法使硬件加速工作:https://superuser.com/questions/1482586/cannot-launch-an-x86-android-emulator-using-hyperv-but-can-with- haxm-为什么

但是,使用 Visual Studio 2017,我可以在“开始”菜单中使用“Visual Studio Emulator for Android”,如下所示:

在此输入图像描述

我将启动其中一个模拟器,它将出现在 Visual Studio 2017 中进行调试,如下所示:

在此输入图像描述

但是,在“适用于 Android 的 Visual Studio 模拟器”中启动后,Visual Studio 2019 不会在 Visual Studio 中显示模拟器。我需要配置什么才能使其正常工作吗?

visual-studio xamarin.android xamarin xamarin.forms visual-studio-emulator

2
推荐指数
1
解决办法
3699
查看次数

每次在我的 Windows PC 上关闭 Visual Studio 时,有没有办法阻止 Docker 删除容器?

我创建了一个应用程序,它使用 Docker 创建容器。该应用程序第一次构建大约需要 20-30 分钟,此后构建速度非常快。

在我的 MAC 上;容器会一直保留到我删除它们为止。但是,在我的 Windows PC 上;每次关闭 Visual Studio 2017 时都会自动删除容器。因此,每次我在 Windows PC 上打开全新的解决方案时,我都必须坐下来等待解决方案的构建。

每次在我的 Windows PC 上关闭 Visual Studio 时,有没有办法阻止 Docker 删除容器?

到目前为止,我已经在 Docker 桌面和 Visual Studio/Options 中寻找了一个设置,但是我找不到它。我也谷歌了这个。

c# windows macos visual-studio docker

2
推荐指数
1
解决办法
175
查看次数