对 LINQ 中的值应用子字符串
我使用 LINQ 绑定下拉值,如下所示
var varResult =
(from OppData in dtOpp.AsEnumerable()
select new
{
TEXT = OppData.Field<object>(sColName), //column value
VALUE = sColName // column Name
}
).Distinct();
然后使用 LINQtoDataTable 函数将代码转换为数据表。
dtTemp = LINQToDataTable(varResult);
然后下拉菜单被绑定,如下所示;
ddlTemp.DataSource = dtTemp;
ddlTemp.DataTextField = "TEXT";
ddlTemp.DataValueField = "VALUE";
ddlTemp.DataBind();
现在,下拉列表为其中一列(员工加入日期)绑定的值的格式为08/09/2011~Y,因为它是直接从数据库获取绑定的。我希望在日期上应用子字符串,使其格式为 08/09/2011。如何在 LINQ 查询上应用子字符串?
I am binding the dropdown values using LINQ as below
var varResult =
(from OppData in dtOpp.AsEnumerable()
select new
{
TEXT = OppData.Field<object>(sColName), //column value
VALUE = sColName // column Name
}
).Distinct();
Then the code is converted to datatable using LINQtoDataTable Function.
dtTemp = LINQToDataTable(varResult);
Then the dropdown is binded as seen below;
ddlTemp.DataSource = dtTemp;
ddlTemp.DataTextField = "TEXT";
ddlTemp.DataValueField = "VALUE";
ddlTemp.DataBind();
Now the value that dropdown binds for one of the column, (Employee Joining date) is in format of 08/09/2011~Y, because it is directly getting bind from database. I wish to apply substring on the date so that it is in format of 08/09/2011. How to apply substring on the LINQ queries?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 LINQ 查询中使用匿名类型中的
TEXT
字段作为string
并在查询期间格式化值:类似这样的内容。您还可以提供更有意义的日期表示格式,例如:Aug 09, 2011 等。
Use your
TEXT
field in your anonymous type in LINQ query asstring
and format value during query:Somethign like this. Also you can provide more meaningful format of date representation, ex: Aug 09, 2011, etc.