例如repeater显示如下数据:
a b c d 1
e f g h 2
h i j k 1
.... 这是一张表存储的数据。但是我想对第5列的数据进行格式化。例如:1,我不是让其直接显示1,而是显示中国。2,是显示美国。但数据一绑定,就会直接显示1,2。现在该怎么办?
a b c d 1
e f g h 2
h i j k 1
.... 这是一张表存储的数据。但是我想对第5列的数据进行格式化。例如:1,我不是让其直接显示1,而是显示中国。2,是显示美国。但数据一绑定,就会直接显示1,2。现在该怎么办?
解决方案 »
- gridview增加一列,类型是ButtonField?
- 奇怪的问题,如何向别的网站发送参数
- 如何将选定的一段日期转成datagrid的字段??
- GridView 显示出的时间格式很杯具。。。
- 如何控制DataGrid编辑列的列宽
- 什么是MVC模式?用ASP.net的codebehind方式开发出来的系统算是MVC模式吗?
- 请教关于asp.net安装问题
- 有谁做过“互联星空”接口平台的请进来,有报酬呀!
- 求linq;在group by 的分组依据为多个字段的情况下
- 我有老婆了,有人看上我了怎么办!!
- 【高分100分,不够再加】关于编辑器中未闭合标签的问题
- DataGrid中模版列Checkbox的选中,删除问题。
<form id="form1" runat="server">
<div>
<asp:Repeater ID="Repeater1" runat="server" OnItemDataBound="Repeater1_ItemDataBound">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "au_id" ) %>'></asp:Label>
<asp:Label ID="Label2" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "state" ) %>'></asp:Label>
<br />
</ItemTemplate>
</asp:Repeater>
</div>
</form>//aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
SqlConnection cn = new SqlConnection(@"Server=.\SQLEXPress;uid=sa;pwd=password;Database=Pubs");
string strSQL = "select * from authors";
SqlCommand cmd = new SqlCommand(strSQL, cn);
cn.Open();
SqlDataReader dr = cmd.ExecuteReader();
Repeater1.DataSource = dr;
Repeater1.DataBind();
dr.Close();
cn.Close();
}
}protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
Label label2;
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
label2 = (Label)e.Item.FindControl("label2");
switch(label2.Text)
{
case "CA":
label2.Text = "加州";
break;
default:
label2.Text = "XX";
break;
}
}
}