我很难从miscrosoft网站上发现的日期中删除前导零.
DateTime date1 = new DateTime(2008, 8, 18);
Console.WriteLine(date1.ToString("(M) MMM, MMMM",
CultureInfo.CreateSpecificCulture("en-US")));
// Displays (8) Aug, August
Run Code Online (Sandbox Code Playgroud)
完全不适用于此.
这是我的代码:
string date = '2013-04-01'
DateTime billrunDate = Convert.ToDateTime(date);
string test = billrunDate.ToString("M");
Run Code Online (Sandbox Code Playgroud)
现在测试了 01 April
我只需要它4在字符串或int idc谢谢!
编辑如果我这样做:
billrunDate.ToString("(M)");
Run Code Online (Sandbox Code Playgroud)
我明白了(4),但我不需要()
编辑2:这很有效
string test = billrunDate.ToString(" M ");
string testTwo = test.Trim();
Run Code Online (Sandbox Code Playgroud)
非常非常难看
我正在尝试使用控制台应用程序从另一个类调用方法.我尝试调用的类不是静态的.
class Program
{
static void Main(string[] args)
{
Program p = new Program();
var myString = p.NonStaticMethod();
}
public string NonStaticMethod()
{
return MyNewClass.MyStringMethod(); //Cannot call non static method
}
}
class MyNewClass
{
public string MyStringMethod()
{
return "method called";
}
}
Run Code Online (Sandbox Code Playgroud)
我收到错误:
无法在静态上下文中访问非静态方法"MyStringMethod".
如果我将MyStringMethod移动到类程序,这是有效的.我怎么能成功呢?我不能使类静态也不能使方法.
我与Linq一起使用Entity Framework来填充我的网格视图.我想从excel获得与Linq相同的数据.此外,同一个Excel工作表中的第二个选项卡应来自另一个Linq查询.
什么是最简单,最好的方法?
我在更新面板中有一个表.此表从后面的代码中填充,并且还添加了一个按钮.该按钮触发Javascript.因为这个按钮触发了Javascript我不需要按钮来进行回发.有没有办法禁用此回发?
这是我用于在每个行的表格单元格中设置图像按钮的代码.
ImageButton ibtnTableOneNewComment = new ImageButton();
ibtnTableOneNewComment.ImageUrl = "~/img/Pencil.png";
ibtnTableOneNewComment.OnClientClick = "setDiscription('test', 'testy')";
tabCell.Controls.Add(ibtnTableOneNewComment);
Run Code Online (Sandbox Code Playgroud)
表头在asp中设置,其余来自后面的代码.
<asp:UpdatePanel runat="server" ID="up_tableMain" UpdateMode="Conditional">
<ContentTemplate>
<asp:Table runat="server" ID="tbl_main">
...Headers...
</asp:Table>
</ContentTemplate>
</asp:UpdatePanel>
Run Code Online (Sandbox Code Playgroud) 我正在和ajax一起使用一个实体.我希望在使用JavaScript创建的网格中使用实体框架提供完整的表格.我目前发送的表格少于140行.我的代码工作,如果我在表中只有50行,我得到以下错误:
{"Message":"Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property.","StackTrace":" at System.Web.Script.Serialization.JavaScriptSerializer.Serialize(Object obj, StringBuilder output, SerializationFormat serializationFormat)\r\n at System.Web.Script.Serialization.JavaScriptSerializer.Serialize(Object obj, SerializationFormat serializationFormat)\r\n at System.Web.Script.Serialization.JavaScriptSerializer.Serialize(Object obj)\r\n at System.Web.Script.Services.RestHandler.InvokeMethod(HttpContext context, WebServiceMethodData methodData, IDictionary`2 rawParams)\r\n at System.Web.Script.Services.RestHandler.ExecuteWebServiceCall(HttpContext context, WebServiceMethodData methodData)","ExceptionType":"System.InvalidOperationException"}
Run Code Online (Sandbox Code Playgroud)
在我的网络统计数据中,我的响应正文中的XMLHttpRequest出现500错误,我有错误,如上所示.如果我将行数限制为50,我可以让页面正常工作,我可以在响应正文中看到我的数据.以下代码是将实体数据发送到javascript所需的所有代码.JavaScript的:
$(function() {
$.ajax({
url: "EditFeedApac.aspx/GetApacData",
type: "POST",
contentType: "application/json",
success: function (result) {
console.log(result.d);
},
error: showError
});
});
Run Code Online (Sandbox Code Playgroud)
C#
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public static IEnumerable<PreApacData> GetApacData()
{ …Run Code Online (Sandbox Code Playgroud) 我有一个jQuery的可排序函数的问题.当我的页面使用更新面板进行回发时,动态表的排序不再起作用.按下图像按钮时会触发回发.按下图像按钮时,会有一个新行,其中包含子表.
我尝试了这3个JavaScript代码,但它们似乎只是第一次工作.打开子表后,它们不起作用.
你们可能知道一个JavaScript解决方案来解决这个问题吗?
我的第一次尝试:
$(function(){
$('table[id*="tbl_main"]').tablesorter();
});
Run Code Online (Sandbox Code Playgroud)
我的第二次尝试:
$(document).ready(function(){
$('table[id*="tbl_main"]').tablesorter();
});
Run Code Online (Sandbox Code Playgroud)
我的第三次尝试:
function pageLoad() {
$(function () {
$("#pager").unbind();
$('table[id*="tbl_main"]')
.tablesorter()
.tablesorterPager({ container: $("#pager") });
}
)}
Run Code Online (Sandbox Code Playgroud) javascript jquery updatepanel tablesorter jquery-ui-sortable
我有2个现有的功能.一个我无法编辑(getServiceNames),在第二个我需要设置一个字符串(getDataTableOne).我想在同一个类中使用函数设置此字符串(getAllExceptNiServiceNames),但他给我这个错误,因为我想编辑的函数是静态的.
对象引用是非静态字段,方法或属性'Queries.getAllExceptNiServiceNames()'
我无法删除函数的静态属性,我也无法创建一个字符串对象.什么是最好的解决方法?
public static DataSet getDataTableOne()
{
string serviceNameFilterLineThree = getAllExceptNiServiceNames(); //ERROR
}
public static DataSet getServiceNames()
{
DataSet ds = new DataSet();
string query_select = "select test";
ds = QualityGate.fillDataset(query_select);
return ds;
}
public string getAllExceptNiServiceNames()
{
string sql = "";
DataSet ds = getServiceNames();
int i = 0;
foreach (DataRow theRow in ds.Tables[0].Rows)
{
if (i != 0)
sql += "AND ";
sql += "serviceName = '" + theRow["serviceName"].ToString() + "' ";
i++;
}
return sql;
}
Run Code Online (Sandbox Code Playgroud) 我有一个包含一个表的数据集.我想将此表与Linq一起转换为列表.
这段代码工作正常:
var list = dsUniqueIds.Tables[0].AsEnumerable()
.Select(r => new { column1 = r.Field<string>("UniqueIDs") }).ToList();
Run Code Online (Sandbox Code Playgroud)
但是当我尝试在这样的列表中更改强制转换时:
List<string> list = dsUniqueIds.Tables[0].AsEnumerable()
.Select(r => new { column1 = r.Field<string>("UniqueIDs") })
.ToList();
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
Cannot implicitly convert type
'System.Collections.Generic.List<AnonymousType#1>' to
'System.Collections.Generic.List<string>
Run Code Online (Sandbox Code Playgroud)
我需要在列表中使用jQuery在文本框上自动完成此数据.为了将数据提供给jQuery,我使用JavaScriptSerializer和Serialize(list).Serialize(list)不适用于var.如果我使用var,我只能在JavaScript中获取对象.如果我用foreach填充列表,这可以正常工作.但是我想和Linq一起尝试,我不知道为什么它不起作用.
任何人都知道为什么这不起作用?
我想从服务器读取 xls。我成功地使用 WebClient 下载了文件,但现在我想在不保存文件的情况下打开它。
var request = WebRequest.Create(location);
var response = request.GetResponse();
var stream = response.GetResponseStream();
var document = SpreadsheetDocument.Open(stream, false);
if (stream != null) stream.Close();
Run Code Online (Sandbox Code Playgroud)
我的代码在 SpreadsheetDocument.Open 上停止,它给出了以下错误:
无法对不支持查找的流进行操作。
我做错了什么,为什么我无法打开文档?
c# ×8
javascript ×3
jquery ×3
excel ×2
linq ×2
asp.net ×1
datetime ×1
pagemethods ×1
static ×1
stream ×1
tablesorter ×1
updatepanel ×1
webrequest ×1