ASP.NET:如何显示在GridView从数据库返回不同的值 [英] ASP.NET: How to display a different value returned from a database in a GridView

查看:170
本文介绍了ASP.NET:如何显示在GridView从数据库返回不同的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

标记:

<asp:GridView ID="GridView1" runat="Server">
   <Columns>
      <asp:BoundField DataField="status_column" HeaderText="Status" />
      <asp:BoundField ...
      <asp:BoundField ...
   </Columns>
</asp:GridView>

code:

GridView1.DataSource = _dataSet
DataBind()

存储在我的数据库中的值是整数,1 - 9每个值都有,我想显示在我的GridView控件相关的字符串值。例如:1 =活动; 2 =待机;等我将如何过滤传入的数据,所以我可以显示相关的字符串值,而不是从我的表中的整数?

The values stored in my database are integers, 1 - 9. Each value has an associated string value that I want displayed in my GridView. Ex: 1 = "Active"; 2 = "On Hold"; etc. How would I filter the incoming data so I can display the associated String value instead of the Integers from my table?

推荐答案

您有两种选择:


  1. 修改您的DataSet中,这样它会
    containt一列字符串
    重数据你presentation
    想展示。

  2. 使用一个TemplateField
    包含一个标签。订阅
    的OnRowDataBound事件
    GridView控件,并获得该标签与
    e.Row.FindControl(LabelID),投
    在e.Row.DataItem您的DataRow,
    并指定字符串重新presentation
    你的整数值存在。

我建议不要张贴anishmarokey的解决方案,因为查询是不是这个正确的位置。觉得有点大做大,有关本地化的实例。不会与该解决方案的工作,但与两个我建议的解决方案。

I would advise against the solution posted by anishmarokey, because the query is not the correct place for this. Think a little big bigger, about localization for instance. Wouldn't work with that solution, but with both of my suggested solutions.

EDIT1
从我Similiar answeres关于OnRowDataBound事件。如果这些不帮你,我怕你需要使用谷歌找到更多的例子:结果
<一href=\"http://stackoverflow.com/questions/2272015/programmatically-access-gridview-columns-and-manipulate/2272058#2272058\">Programmatically访问的GridView列和操作结果
<一href=\"http://stackoverflow.com/questions/2458351/custom-gridview-delete-button/2458978#2458978\">Custom GridView的删除按钮结果
<一href=\"http://stackoverflow.com/questions/2985554/how-to-bind-a-complex-dictionary-to-a-gridview-in-asp-net/2985993#2985993\">How绑定复杂字典到GridView在asp.net?

EDIT2
我已经写了进一步阐述这个主题的一篇文章:<一href=\"http://www.tomot.de/en-us/article/7/asp.net/gridview-overview-of-different-ways-to-bind-data-to-columns\" rel=\"nofollow\">http://www.tomot.de/en-us/article/7/asp.net/gridview-overview-of-different-ways-to-bind-data-to-columns

这篇关于ASP.NET:如何显示在GridView从数据库返回不同的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆