小编The*_*mpp的帖子

无法启动Web服务器

我在visual studio 2012中有asp.net web应用程序项目.当我想启动它时,我有以下错误:

无法启动IIS Express Web服务器:端口"4012"正在使用中

这个问题来自于什么.我怎么解决它?

asp.net iis-express visual-studio-2012

63
推荐指数
5
解决办法
8万
查看次数

在GridView中的TemplateField上的标头

当我使用超链接创建"TemplateField"时,如何在GridView中创建标题"全名"?例如,我希望TemplateField中的这些行具有标题"全名".

<asp:GridView ID="CustomersGridView" runat="server" AutoGenerateColumns="False" >
        <Columns>

            <asp:TemplateField>
                <ItemTemplate>
                <asp:HyperLink ID="HyperLink1" runat="server" Text='<%# Eval("FirstName") + " " + Eval("LastName")  %>'
                     NavigateUrl="CarTest.aspx" > </asp:HyperLink>        
                </ItemTemplate>
            </asp:TemplateField>

        </Columns>
</asp:GridView>
Run Code Online (Sandbox Code Playgroud)

asp.net templates gridview header

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

在ListView控件中查找控件

我想在"ListView"控件中找到ID ="Label"的"Label"控件.我试图使用以下代码执行此操作:

((Label)this.ChatListView.FindControl("Label")).Text = "active";
Run Code Online (Sandbox Code Playgroud)

但是我得到了这个异常:对象引用未设置为对象的实例.

这有什么不对?

这是aspx代码:

<asp:ListView ID="ChatListView" runat="server" DataSourceID="EntityDataSourceUserPosts">
    <ItemTemplate>
        <div class="post">
            <div class="postHeader">
                <h2><asp:Label ID="Label1" runat="server" 
                    Text= '<%# Eval("Title")  + " by " + this.GetUserFromPost((Guid?)Eval("AuthorUserID")) %>' ></asp:Label></h2>
                <asp:Label ID="Label" runat="server" Text="" Visible="True"></asp:Label>
                <div class="dateTimePost">
                   <%# Eval("PostDate")%>
                </div>
            </div>
            <div class="postContent">
                <%# Eval("PostComment") %>
            </div>
        </div>
    </ItemTemplate>

</asp:ListView>
Run Code Online (Sandbox Code Playgroud)

c# asp.net webforms exception

6
推荐指数
2
解决办法
3万
查看次数

将C#数组传递给Javascript

将C#数组传递给javascript变量的最佳方法是什么?

我有示例代码,但是这个返回字符来自C#数组,我希望以正常方式返回,就像javascript数组中的逐字一样;

C#代码背后:

 public string[] names = { "John", "Pesho", "Maria"};
 public JavaScriptSerializer javaSerial = new JavaScriptSerializer();
Run Code Online (Sandbox Code Playgroud)

javascript代码:

 <script>
    var a = '<%= this.javaSerial.Serialize(this.names) %>';
    for (var i = 0; i < a.length; i++) {
        console.log(a[i]);
    }
 </script>
Run Code Online (Sandbox Code Playgroud)

此脚本返回单个char数组中"names"数组中的所有单词.我想像["John"] ["Pesho"]那样以正常的方式回归......

将C#数组传递给javascript的最佳方法是什么?

当我运行此代码时,我在Chrome浏览器的控制台中获得以下内容:

[ Profile.aspx:44
" Profile.aspx:44
v Profile.aspx:44
a Profile.aspx:44
l Profile.aspx:44
e Profile.aspx:44
r Profile.aspx:44
i Profile.aspx:44
" Profile.aspx:44
, Profile.aspx:44
" Profile.aspx:44
p Profile.aspx:44
e Profile.aspx:44
s Profile.aspx:44
h Profile.aspx:44
o Profile.aspx:44
" Profile.aspx:44
, Profile.aspx:44
" Profile.aspx:44 …
Run Code Online (Sandbox Code Playgroud)

javascript c# asp.net arrays

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

带有属性的 XML 模式限制

在 XML Schema 中,如何使元素Age必须restriction允许写入最大值为 10 和最小值为 1 的整数,在元素内部Age而且元素Age具有属性?

<xsd:element name="Age">
  <xsd:complexType>
here i want to have restriction to control max and min value inside Age element
    <xsd:attribute name="type" type="xsd:string" use="required" />
  </xsd:complexType>
</xsd:element>
Run Code Online (Sandbox Code Playgroud)

没有警告的 XML 代码

<Age type="sth">
 5 
</Age>
Run Code Online (Sandbox Code Playgroud)

带有警告的 XML 代码

<Age type="sth">
 22
</Age>
Run Code Online (Sandbox Code Playgroud)

xml xsd

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

ADO.Net实体框架事务

我想问一下在ADO.Net Entity Framework(调用,回滚,提交)中使用事务的正确方法是什么?我有这个代码,但这给了我一个例外

"Invalid operation. The connection is closed." 
Run Code Online (Sandbox Code Playgroud)

(在此代码中NorthwindEntities继承"DBContext")

NorthwindEntities context = new NorthwindEntities();
DbTransaction tran = context.Database.Connection.BeginTransaction();
var cust = context.Customers.FirstOrDefault(x => x.CustomerID == "BOLID");
cust.Country = "Nigeria";
context.SaveChanges();
tran.Rollback();
Run Code Online (Sandbox Code Playgroud)

c# sql ado.net entity-framework transactions

3
推荐指数
1
解决办法
1966
查看次数

同步和异步请求之间有什么区别?(异步=真/假)

当我使用方法时,async=false和之间有什么区别?async=trueopenXMLHttpRequest

function GetXML() {

    if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp = new XMLHttpRequest();
    }
    else {// code for IE6, IE5
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange = test
    xmlhttp.open("GET", "PlanetCafe.xml", true);
    xmlhttp.send(null);
}
Run Code Online (Sandbox Code Playgroud)

javascript ajax

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

在SQL Server中存储图像的最佳方法

在SQL Server中存储映像的正确方法是哪种?有什么方法可以使用ADO.NET实体框架存储它们吗?我需要一些好的资源,以最好的现代方式来做到这一点。

c# sql-server asp.net entity-framework image

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

在中继器控制中找不到标签控制

我想TextLabel在后面的代码中使用带有ID的Label控件,但是这给了我以下异常Object reference not set to an instance of an object.异常是在代码隐藏文件的这行代码中:

  Label label = e.Item.FindControl("TextLabel") as Label;

  string text = label.Text;
Run Code Online (Sandbox Code Playgroud)

我在这里弄错了什么?如何在代码后面找到"TextLabel"控件?

aspx代码:

<asp:Repeater ID="UserPostRepeater" runat="server" OnItemDataBound="UserPostRepeater_ItemDataBound">
    <HeaderTemplate>
    </HeaderTemplate>
    <ItemTemplate>

        <asp:Label ID="TextLabel" runat="server" Text="Label"></asp:Label>
    </ItemTemplate>
    <FooterTemplate>
    </FooterTemplate>
</asp:Repeater>
Run Code Online (Sandbox Code Playgroud)

后台代码:

protected void UserPostRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
    BlogProfileEntities blogProfile = new BlogProfileEntities();
    Label label = e.Item.FindControl("TextLabel") as Label;
    string text = label.Text;
}
Run Code Online (Sandbox Code Playgroud)

c# asp.net repeater exception

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

对于循环使用C#代码隐藏方法

当我在代码后面调试它让我进入"测试"方法只有一次,而不是三次,为什么?我看到我有javascript"for loop",它应该在C#"Test"方法中进行三次.但这只是一次,这是正常的吗?我想在javascript"for loop"中说三次"Test"方法.问题出在哪儿 ?

aspx代码:

<script>
    $(function () {
        for (var i = 0; i < 3; i++) {

            console.log("active");
            var a = '<%= this.Test() %>';
        }
    });
</script>
Run Code Online (Sandbox Code Playgroud)

C#代码背后:

    public string Test()
    {
        int a = 1;
        return "active";
    }
Run Code Online (Sandbox Code Playgroud)

javascript c# asp.net for-loop

0
推荐指数
1
解决办法
664
查看次数