我似乎在圈子里跑来跑去,并且在过去的几个小时里一直这样做.
我想从一个字符串数组填充datagridview.我已经读过它不可能直接了,我需要创建一个将字符串保存为公共属性的自定义类型.所以我上了一堂课:
public class FileName
{
private string _value;
public FileName(string pValue)
{
_value = pValue;
}
public string Value
{
get
{
return _value;
}
set { _value = value; }
}
}
Run Code Online (Sandbox Code Playgroud)
这是容器类,它只是一个具有字符串值的属性.我现在想要的是当我将其数据源绑定到List时,该字符串将出现在datagridview中.
我也有这个方法,BindGrid(),我想填充datagridview.这里是:
private void BindGrid()
{
gvFilesOnServer.AutoGenerateColumns = false;
//create the column programatically
DataGridViewTextBoxColumn colFileName = new DataGridViewTextBoxColumn();
DataGridViewCell cell = new DataGridViewTextBoxCell();
colFileName.CellTemplate = cell; colFileName.Name = "Value";
colFileName.HeaderText = "File Name";
colFileName.ValueType = typeof(FileName);
//add the column to the datagridview
gvFilesOnServer.Columns.Add(colFileName);
//fill the string …Run Code Online (Sandbox Code Playgroud) 为了改进一个较旧的项目,我被迫使用VS 2008和Framework 3.5 - 我有问题,edmx显示奇怪的行为,而不是根据需要更新实体.
edmx抛出了上面的错误,但是当我转到相应的表并右键单击它 - "从数据库更新模型"没有变化时,错误仍然存在.
如果我通过选择它并按del删除图表中的表格,那么在模型浏览器中它会从.Database中消失但是当点击"从数据库更新模型"时我无法在"添加"列表中看到我,所有我可以做的是"刷新"表格,因为我仍然在刷新列表中看到它(这不应该发生,因为我删除了它!)
我有一个经典的问题,在浏览器的底部定位页脚.我已经尝试了一些方法,包括http://ryanfait.com/resources/footer-stick-to-bottom-of-page/,但结果不好:我的页脚总是一直出现在FF和浏览器窗口的中间IE浏览器.
在HTML中我得到了这个简单的结构
<form>
...
<div class=Main />
<div id=Footer />
</form>
Run Code Online (Sandbox Code Playgroud)
这是与css页脚问题相关的css代码:
*
{
margin: 0;
}
html, body
{
height: 100%;
}
#Footer
{
background-color: #004669;
font-family: Tahoma, Arial;
font-size: 0.7em;
color: White;
position: relative;
height: 4em;
}
.Main
{
position:relative;
min-height:100%;
height:auto !important;
height:100%;
/*top: 50px;*/
margin: 0 25% -4em 25%;
font-family: Verdana, Arial, Tahoma, Times New Roman;
font-size: 0.8em;
word-spacing: 1px;
line-height: 170%;
/*padding-bottom: 40px;*/
}
Run Code Online (Sandbox Code Playgroud)
我哪里做错了?我真的尝试了一切.如果我错过了任何有用的信息,请告诉我.
感谢您提前提出任何建议.
问候,
谢谢大家的答案.它适用于:
position:absolute;
width:100%;
bottom:0px;
Run Code Online (Sandbox Code Playgroud)
设置位置:由于某种原因,在IE中无法正常工作(仍然在浏览器中间显示页脚),仅适用于FF.
我有一个包含此方法的Web服务:
[WebMethod]
public static List<string> GetFileListOnWebServer()
{
DirectoryInfo dInfo = new DirectoryInfo(HostingEnvironment.MapPath("~/UploadedFiles/"));
FileInfo[] fInfo = dInfo.GetFiles("*.*", SearchOption.TopDirectoryOnly);
List<string> listFilenames = new List<string>(fInfo.Length);
for(int i = 0; i < fInfo.Length; i++)
{
listFilenames.Add(fInfo[i].Name);
}
return listFilenames;
}
Run Code Online (Sandbox Code Playgroud)
这将返回文件夹中的文件名列表.当我调试应用程序时,它工作正常.
我想要做的是从winform应用程序调用这个webservice方法.我添加了对web服务的.dll的引用,这就是我调用上面方法的方法:
private void Form1_Load(object sender, EventArgs e)
{
List<string> files = TestUploaderWebService.Service1.GetFileListOnWebServer();
}
Run Code Online (Sandbox Code Playgroud)
上面的代码不起作用 - 当它进入方法时,Web应用程序的路径为null,HostingEnvironment类的许多属性也为null.在尝试从另一个winform应用程序调用Web服务方法时,我的错误在哪里?
请注意,Web服务是在Visual Web Developer Express中创建的,而win C#表示的是winform; 这就是我必须在winform应用程序中添加Web服务dll作为参考的原因.我没有完整的Visual Studio,这可以让我在两个项目中都有一个解决方案.
我是网络服务的新手.
PS - 我喜欢这里的文本格式化:)
表单身份验证票证的另一个问题是过早到期.我需要使用滑动Expiration设置为true.我已阅读论坛并了解精度损失的问题,如果请求仅在到期时间的一半之后进行,则只会更新故障单.
问题:在我的webconfig中,我有以下内容:
<authentication mode="Forms">
<forms timeout="20" name="SqlAuthCookie" protection="All" slidingExpiration="true" />
</authentication>
<sessionState timeout="20" />
<authorization>
Run Code Online (Sandbox Code Playgroud)
只有在20分钟间隔内没有请求时,用户才必须注销并重定向到login.aspx.问题是用户正在发出请求,但仍然会被抛到登录页面.这不应该发生.我想做的是为每个请求手动重置SqlAuthCookie.
以下是我的代码.它在context.AcquireRequestState上调用.
void context_AcquireRequestState(object sender, EventArgs e)
{
HttpContext ctx = HttpContext.Current;
ResetAuthCookie(ctx);
}
private void ResetAuthCookie(HttpContext ctx)
{
HttpCookie authCookie = ctx.Request.Cookies[FormsAuthentication.FormsCookieName];
if (authCookie == null)
return;
FormsAuthenticationTicket ticketOld = FormsAuthentication.Decrypt(authCookie.Value);
if (ticketOld == null)
return;
if (ticketOld.Expired)
return;
FormsAuthenticationTicket ticketNew = null;
if (FormsAuthentication.SlidingExpiration)
ticketNew = FormsAuthentication.RenewTicketIfOld(ticketOld);
if (ticketNew != ticketOld)
StoreNewCookie(ticketNew, authCookie, ctx);
}
private void StoreNewCookie(FormsAuthenticationTicket ticketNew, HttpCookie authCookie, HttpContext ctx) …Run Code Online (Sandbox Code Playgroud) 我需要一个Uri验证方法.所以,字符串如:
" http://www.google.com ","www.google.com","google.com"
..必须验证为Uri的.而且像"google"这样的普通字符串也不能被验证为Uri.要进行此检查,我使用两种方法:UriBuilder和Uri.TryCreate().
UriBuilder的问题是我给它的任何字符串,它返回一个Uri.当我在其构造函数中传递一个普通字符串时,它给它一个方案并返回" http:// google / ",这不是我想要的行为.
Uri.TryCreate()的问题在于,虽然它适用于" http://www.google.com "和"www.google.com",但当我给它"google.com"时它不会验证是作为一个乌里.
我想过对字符串进行检查,如果它以http://或www开头,将字符串发送到UriBuilder类,但这对"google.com"也没有帮助,"google.com"也必须是Uri.
如何验证像"google.com"这样的东西作为Uri,而不是"google"?检查.com,.net,.org字符串的结尾似乎不灵活.
这是关于最佳编码实践的问题.我想知道如何最好地避免在.NET应用程序中硬编码字符串和值的共识.到目前为止我在以前工作过的地方看到了什么:
创建一个静态类ApplicationStrings并声明其中的所有字符串和值:
public static class ApplicationStrings
{
#region constants
public const string APPLICATION_NAME = "X";
public const string APPLICATION_RESOURCEMANAGER_NAME = "ResourceManagerX";
public const string APPLICATION_DEFAULT_LOGFILENAME = "log.txt";
}
Run Code Online (Sandbox Code Playgroud)但是,不是第三种方法,只是另一种硬编码?有这样一堂课有意义吗?好处是所有字符串都在一个地方,但是真的避免使用硬编码吗?
此外,如果你已经养成了这种情况的其他习惯,请随时发布.
有时我无法理解最简单的事情,我确信这是在我的脸上,我只是没有看到它.我试图在这个简单的类中为方法创建一个委托:
public static class BalloonTip
{
public static BalloonType BalType
{
get;
set;
}
public static void ShowBalloon(string message, BalloonType bType)
{
// notify user
}
}
Run Code Online (Sandbox Code Playgroud)
现在,这个Action <>应该创建委托而不实际声明一个关键字"委托",我是否理解正确?然后:
private void NotifyUser(string message, BalloonTip.BalloonType ballType)
{
Action<string, BalloonTip.BalloonType> act;
act((message, ballType) => BalloonTip.ShowBalloon(message, ballType));
}
Run Code Online (Sandbox Code Playgroud)
这无法编译.为什么?
(顺便说一句,我需要这个委托而不是直接调用ShowBalloon()的原因是,调用必须来自另一个线程而不是UI,所以我想我需要Action <>)
谢谢,
我有一个关于Windows.Forms应用程序中的委托的问题.
有两种形式:
主窗体,有一个名为"设置"的按钮.
"设置"表单,这是"子"形式.
当我单击主窗体中的"设置"按钮时,它会打开"设置"窗体的实例.
我的问题是,当我打开它时,我需要将一个变量传递给Settings表单.这样新表单将显示变量文本.我不知道如何检索子项"设置"表单中的信息.我是通过在线教程完成此操作,无法从教程中了解如何阅读目标表单中的信息.
这是我到目前为止所做的,主要形式的代码:
public partial class MainForm : Form
{
/// <summary>
/// delegate to send data between forms
/// </summary>
public delegate void PageInfoHandler(object sender, PageInfoEventArgs e);
/// <summary>
/// event of the delegate
/// </summary>
public event PageInfoHandler PageInfoRetrieved;
//other stuff, events blabla
private void toolStripBtnSettings_Click(object sender, EventArgs e)
{
PageInfoEventArgs args = new PageInfoEventArgs(SomeString);
this.OnPageInfoRetrieved(args);
SettingsForm settingsForm = new SettingsForm();
settingsForm.ShowDialog();
}
private void OnPageInfoRetrieved(PageInfoEventArgs args)
{
if (PageInfoRetrieved != null)
PageInfoRetrieved(this, args); …Run Code Online (Sandbox Code Playgroud) 我的应用程序需要创建在浏览器中有3个不同时区显示的startDate的对象.日期还必须包括确切的时间.日期应该以这样的方式存储:它允许查询"给我所有日期在X和Y之间",并将其解析为3个时区.
我的问题是我应该如何最好地保存(并随后检索)日期和时间,以便我可以在日期范围中稍后查询,我是否应该使用moment.js?我想到的是,将日期和时间都保存在数据库中的单个unix时间戳中,并且在读取时只需将其解析为具有该特定时区的日期和时间.这种方法是正确的,还是应该将其保存为普通的javascript日期?mongoDB可以将unix时间戳作为日期范围查询还是需要普通的Date对象?
谢谢.
c# ×5
.net ×4
winforms ×2
action ×1
asp.net ×1
binding ×1
coding-style ×1
css ×1
datagridview ×1
date ×1
delegates ×1
hard-coding ×1
httpcookie ×1
javascript ×1
mapping ×1
meteor ×1
mongodb ×1
notifyicon ×1
uri ×1
validation ×1
web-services ×1