小编Baz*_*nga的帖子

如何使用C#在<strong>标签之间提取字符串?

说我有一个如下所示的字符串:

"Unneeded text <strong>Needed Text</strong> More unneeded text"
Run Code Online (Sandbox Code Playgroud)

我怎样才能只提取" 需要的文字 "?我猜Regex可能是最简单的方法,但Regex对我来说仍然看起来像象形文字.

c# regex

11
推荐指数
4
解决办法
3万
查看次数

使用EF4获取SQL表的最后一行的最有效方法是什么?

我希望通过表的ID列检索表的最后一行.我目前使用的是什么:

var x = db.MyTable.OrderByDescending(d => d.ID).FirstOrDefault();
Run Code Online (Sandbox Code Playgroud)

有没有办法以更有效的速度获得相同的结果?

c# linq entity-framework entity-framework-4

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

为什么我的ASP.NET LinkBut​​ton没有触发OnClick ="AddToCart_Click"事件?

我现在一直在撞墙挡住整整一天.我正在研究Apress的"在C#中开始使用ASP.NET电子商务",如果有人熟悉该项目的话.在第10章中,我们正在使用PayPal AddToCart和GoToCart功能.这是未触发的事件:

    //Why is this not working?
protected void AddToCartButton_Click1(object sender, EventArgs e)
{
    string productID = Request.QueryString["ProductID"];
    ProductDetails pd = CatalogAccess.GetProductDetails(productId);
    string options = "";
    foreach (Control cnt in attrPlaceHolder.Controls)
    {
        if (cnt is Label)
        {
            Label attrLabel = (Label)cnt;
            options += attrLabel.Text;
        }
        if (cnt is DropDownList)
        {
            DropDownList attrDropDown = (DropDownList)cnt;
            options += attrDropDown.Items[attrDropDown.SelectedIndex] + "; ";
        }
    string productUrl = Link.ToProduct(pd.ProductID.ToString());
    string destination = Link.ToPayPalAddItem(productUrl, pd.Name, pd.Price, options);
    Response.Redirect(destination);
    }
Run Code Online (Sandbox Code Playgroud)

这是LinkBut​​ton的代码:

    <p>
    <asp:LinkButton ID="AddToCartButton" runat="server" CausesValidation="False" …
Run Code Online (Sandbox Code Playgroud)

c# asp.net e-commerce

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

如何设置此正则表达式的最大长度?

此验证适用于允许字母数字字符、空格和破折号,但我无法将最大长度设置为 23。

正则表达式: (^\w+\s*(-?)(\s*\w+\s*)(\w+)$){0,23}

我需要通过的案例:

  • 温斯顿1-塞勒姆6
  • 温斯顿-塞勒姆
  • 温斯顿塞勒姆
  • 1-23
  • 带空格的 word2

我需要失败的案例:

  • -纽伯蒂-洛斯-
  • 12345678901234567890123444

regex

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

如何使用FtpWebRequest上传图像?

我一直致力于为客户构建一个功能,使他们能够从www.site1.com上传图像,将图像URL存储到数据库,并将图像存储到www.site2.com/images上的文件中.我已经设法将文件上传到目标位置,但是当我尝试打开并查看图像时,据说它包含错误.我从来没有真正使用过图像,所以我很茫然.

这是用于上传文件的方法:

public static void UpLoadImage(Stream image, string target)
    {
        FtpWebRequest req = (FtpWebRequest)WebRequest.Create("ftp://www.site2.com/images/" + target);
        req.UseBinary = true;
        req.Method = WebRequestMethods.Ftp.UploadFile;
        req.Credentials = new NetworkCredential("myUser", "myPass");
        StreamReader rdr = new StreamReader(image);
        byte[] fileData = Encoding.UTF8.GetBytes(rdr.ReadToEnd());

        rdr.Close();
        req.ContentLength = fileData.Length;
        Stream reqStream = req.GetRequestStream();
        reqStream.Write(fileData, 0, fileData.Length);
        reqStream.Close();
    }
Run Code Online (Sandbox Code Playgroud)

这是从(image1是HttpPostedFileBase)调用方法的地方:

myObject.UpLoadImage(image1.InputStream, storedTL.ID + "-1.png");
Run Code Online (Sandbox Code Playgroud)

如果有一种方法可以让我的代码工作,或者如果有更好的方法来做到这一点,请帮助.

c# ftpwebrequest asp.net-mvc-3

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

How can jQuery DataTables be applied to AJAX rendered partial view in MVC4?

I have a partial view:

@model List<ADE_ATRS.Models.DistrictsSummaryStatistic>
@{
    bool isPrint = (bool)ViewData["isPrint"];
    string printHeader = ViewData["printHeader"].ToString();
    int totalCount = 0;
    if (ViewData["totalCount"] != null)
    {
        totalCount = (int)ViewData["totalCount"];
    }
}
@if (isPrint)
{
    @Styles.Render("~/Print/css")
}
<div class="content">
    @if (isPrint)
    {
        <div>
            <h2>
                @printHeader
            </h2>
        </div>
    }
    <div>
        <table>
            <thead>
                <tr>
                    <th colspan="2">
                        Counts
                    </th>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <td>
                        Total Count
                    </td>
                    <td style="width: 75px;">
                        @totalCount
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
    <div>
        <table>
            <thead>
                <tr>
                    <th>
                        District
                    </th>
                    <th style="width: …
Run Code Online (Sandbox Code Playgroud)

jquery datatables asp.net-mvc-4

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

是否有Intellij Idea 13的代码片段编辑器?

Visual Studio具有Snippet Designer扩展,可用于创建和管理自定义代码段.是否有像Intellij Idea 13这样的扩展名,或简单地添加自定义代码片段的方法?

ide intellij-idea visual-studio

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

如何在不使用'go'的情况下运行此sql脚本?

我正在尝试创建一个脚本来创建和填充表,然后为我的应用程序创建存储过程来访问它们.我的脚本运行得很好,直到我到达存储过程.我正在尝试将.sql文件读入我的应用程序,然后在一次执行中通过我的连接运行此脚本.有没有什么办法可以从脚本的这个块中删除'go'关键字,让它在一次执行中运行?

if object_id('GetStudentByID') is not null
drop procedure GetStudentByID;
go
create procedure GetStudentByID
(@StudentID INT)
as
select StudentID,FirstName,LastName
from Student
where StudentID = @StudentID;
Run Code Online (Sandbox Code Playgroud)

sql

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