62,025
社区成员
发帖
与我相关
我的任务
分享
<asp:DataList ID="DataList1" runat="server">
<HeaderTemplate>
<table>
<tr>
<td>编号</td>
<td>名称</td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td><%# GetText(Eval("ID").ToString()) %></td>
<td><%# Eval("Name") %></td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:DataList>
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DataList1.DataSource = GetData();
DataList1.DataBind();
}
}
private DataTable GetData()
{
//新建表
DataTable dt = new DataTable();
//定义表结构
dt.Columns.Add("Id", typeof(System.Int32));
dt.Columns.Add("Name", typeof(System.String));
//添加新行
for (int i = 0; i <= 5; i++)
{
DataRow dr = dt.NewRow();
dr[0] = i;
dr[1] = "oec200" + i;
dt.Rows.Add(dr);
}
return dt;
}
public string GetText(string id)
{
return "编号:" + id;
}
declare @table table (id int,[value] int)
insert into @table
select 1,1 union all
select 2,2 union all
select 3,3 union all
select 4,4
select id,case bb.[value] when '1' then '***' when'2' then 'AAA'
else [value] end as [value]
from
( select id,cast([value] as varchar(20)) as [value] from @table) bb
/*
id value
----------- --------------------
1 ***
2 AAA
3 3
4 4
*/