超级简单的问题,各位达人

mahatma_cn 2008-07-11 12:58:11
GridView控件,绑定数据是,如果某些字段需要特殊处理,怎么处理,

例如:有些数据库中字段为数字,但是不能直接显示数字吧?得用使用者易于理解的中文或英文表示。

如:
1 表示 "xxxx"
2 表示 "yyyy"
4 表示 "zzzz"

3KS
...全文
113 19 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
19 条回复
切换为时间正序
请发表友善的回复…
发表回复
wangruibaobei 2008-07-11
  • 打赏
  • 举报
回复
<Columns>
<asp:TemplateField>
<ItemTemplate>
<%#showname(Eval("thisnum").ToString()%>
</ItemTemplate>
</asp:TemplateField>
</Columns>
  • 打赏
  • 举报
回复
一楼的方法要把那列设置成摸版列.用LABLE的.后台找这个控件的ID就可以了
mahatma_cn 2008-07-11
  • 打赏
  • 举报
回复
??????

一楼的方法 要把需要处理的列放置 Lable控件吧?
二楼的方法 那个串字符放置在哪里?
twin21cn 2008-07-11
  • 打赏
  • 举报
回复
1楼2楼的都可以
wxdxy 2008-07-11
  • 打赏
  • 举报
回复
时间不紧的话,我建议看一下linq,这样sql就全在vs2008里搞定了
wxdxy 2008-07-11
  • 打赏
  • 举报
回复
我用的是一楼办法,用的另外一种是在sql语句里写,case when,你查询一下
bollton 2008-07-11
  • 打赏
  • 举报
回复
<%#Eval("thisnum").ToString()=="1"?"XXXX":(Eval("thisnum").ToString()=="2"?"YYYY":"ZZZZ")%>
mahatma_cn 2008-07-11
  • 打赏
  • 举报
回复

<%#showname(Eval("thisnum").ToString()%> 置于何处?是DataFormatString吗?
xqy_2007 2008-07-11
  • 打赏
  • 举报
回复
DataView CreateDataSoureBy()
{
System.Data.DataTable dt = new System.Data.DataTable();
System.Data.DataRow dr;
dt.Columns.Add(new System.Data.DataColumn("列名1", typeof(System.String)));
dt.Columns.Add(new System.Data.DataColumn("列名2", typeof(System.String)));
dt.Columns.Add(new System.Data.DataColumn("列名3", typeof(System.String)));

dr = dt.NewRow();
dr[0] = ;//想要显示的内容
dr[1] = ; //想要显示的内容
dr[2] = ; //想要显示的内容
dt.Rows.Add(dr);

System.Data.DataView dv = new System.Data.DataView(dt);
return dv;
}
brooklyng60 2008-07-11
  • 打赏
  • 举报
回复
1L的,2L的方法都行,
cpp2017 2008-07-11
  • 打赏
  • 举报
回复
thisnum是你的字段名称,这个写在aspx中,注意前面少了个#应该是
<%#showname(Eval("thisnum").ToString()%>
mahatma_cn 2008-07-11
  • 打赏
  • 举报
回复
"thisnum" 是哪里来的?
wwd252 2008-07-11
  • 打赏
  • 举报
回复
恩,都可以的!
jl_lsj 2008-07-11
  • 打赏
  • 举报
回复
都可以的 就看你喜欢那种方式了
stning 2008-07-11
  • 打赏
  • 举报
回复
一楼的行,就看你自己这个数字对应字符串的变动多不多了
dotnet东哥 2008-07-11
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 seesea125 的回复:]
<%showname(Eval("thisnum").ToString()%>
.cs
public string showname(string num)
{
string returnstring;
if(num=="1")
returnstring="xxxx";
if(num=="2")
returnstring="yyyy";
if(num=="4")
returnstring="zzzz";
return returnstring;
}
[/Quote]

后台写方法前面调就行了
panw520 2008-07-11
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 seesea125 的回复:]
<%showname(Eval("thisnum").ToString()%>
.cs
public string showname(string num)
{
string returnstring;
if(num=="1")
returnstring="xxxx";
if(num=="2")
returnstring="yyyy";
if(num=="4")
returnstring="zzzz";
return returnstring;
}

[/Quote]
seesea125 2008-07-11
  • 打赏
  • 举报
回复
<%showname(Eval("thisnum").ToString()%>
.cs
public string showname(string num)
{
string returnstring;
if(num=="1")
returnstring="xxxx";
if(num=="2")
returnstring="yyyy";
if(num=="4")
returnstring="zzzz";
return returnstring;
}
jcrjia 2008-07-11
  • 打赏
  • 举报
回复
在RowDataBound事件里处理
比如

protected void gv_num_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Label lbl_one = e.Row.FindControl("one") as Label;
Label lbl_two = e.Row.FindControl("two") as Label;

if (lbl_one.Text == "1")
lbl_one.Text = "xxxx";
else if(lbl_one.Text=="2")
lbl_one.Text = "yyyy";

if (lbl_two.Text == "0")
lbl_two.Text = "zzzz";
else if (lbl_two.Text == "1")
lbl_two.Text = "wwww";

}
}

62,243

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧