您好,登錄后才能下訂單哦!
這篇文章主要為大家展示了“LinqDataSource控件怎么用”,內(nèi)容簡(jiǎn)而易懂,條理清晰,希望能夠幫助大家解決疑惑,下面讓小編帶領(lǐng)大家一起研究并學(xué)習(xí)一下“LinqDataSource控件怎么用”這篇文章吧。
有人在論壇咨詢LinqDataSource控件如何進(jìn)行組合字段數(shù)據(jù)顯示在下列列表中,其實(shí),很簡(jiǎn)單,就是使用new 重新生成一個(gè)臨時(shí)類即可。下面是完整的代碼。
C# 代碼
using System;
using System.Collections.Generic;
using System.Web;
/// <summary>
///Books 的摘要說明
/// </summary>
public class Books
{
public int Id { get; set; }
public String Author { get; set; }
public String Title { get; set; }
public DateTime PunDate { get; set; }
public Books() { }
public List<Books> GetBooks
{
get
{
return this.GetInternalBooks();
}
}
internal List<Books> GetInternalBooks()
{
List<Books> bs = new List<Books>();
bs.Add(new Books { Id = 1, Author = "孟憲會(huì)", Title = "《ASP.NET 2.0 應(yīng)用開發(fā)技術(shù)》",
PunDate = System.DateTime.Now.AddMonths(-10) });bs.Add(new Books { Id = 2, Author = "孟憲會(huì)", Title = "《Eric Meyer談CSS(卷2)》",
PunDate = System.DateTime.Now });bs.Add(new Books { Id = 3, Author = "孟憲會(huì)", Title = "《Eric Meyer談CSS(卷1)》",
PunDate = System.DateTime.Now.AddMonths(+10) });return bs;
}
}
ASPX 代碼
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="LinqDataSource1"
DataTextField="DataText" DataValueField="Id">
</asp:DropDownList>
<asp:LinqDataSource ID="LinqDataSource1" runat="server"
ContextTypeName="Books" TableName="GetBooks"Select='new(Id,Id.toString() + "--" + Author + "--" +
Title + "--" + PunDate.ToString("yyyy-MM-dd") as DataText)'></asp:LinqDataSource>
</form>
</body>
</html>
***的執(zhí)行結(jié)果將是下面的樣子:
HTML 代碼
<select name="DropDownList1" id="DropDownList1"> <option value="1">1--孟憲會(huì)--《ASP.NET 2.0 應(yīng)用開發(fā)技術(shù)》--2008-07-31</option> <option value="2">2--孟憲會(huì)--《Eric Meyer談CSS(卷2)》--2009-05-31</option> <option value="3">3--孟憲會(huì)--《Eric Meyer談CSS(卷1)》--2010-03-31</option> </select>
以上是“LinqDataSource控件怎么用”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對(duì)大家有所幫助,如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注億速云行業(yè)資訊頻道!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。