你在sql里面做。 也可以用#Eval绑定值外面套一个函数, sql更方便,select classid= case when class_id=1 then '***' when class_id=2 then 'FFF' else 'RR' end from table
1 是可以再Sql语句中处理 2 在ItemDataBound中处理
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,4select 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 */
也可以用#Eval绑定值外面套一个函数,
sql更方便,select
classid= case when class_id=1 then '***'
when class_id=2 then 'FFF'
else 'RR' end
from table
2 在ItemDataBound中处理
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,4select 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
*/
<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;
}