zoukankan      html  css  js  c++  java
  • 更改DataGrid里数据绑定的值

    用DataGrid做数据绑定的时候,如显示性别等,数据库里放的是对应的0或1。在DataGrid里我们一般需要显示的是男或女,而不是0或1,如何实现呢?当然,在数据库查询的时候就可以直接使用case去做,那么如果查询出来是0/1这种情况,怎么在DataGrid把这个数字转换成男/女显示呢?
    在aspx页面里对应的是这样的:
                        <asp:BoundColumn DataField="sex" HeaderText="sex" Visible="False">
                            
    <ItemStyle Width="100px"></ItemStyle>
                        
    </asp:BoundColumn>
                        
    <asp:TemplateColumn HeaderText="性别" ItemStyle-Width="100">
                            
    <ItemTemplate>
                                
    <asp:Label id="lblSex" Runat="server"></asp:Label>
                            
    </ItemTemplate>
                        
    </asp:TemplateColumn>

    在DataGrid的ItemDataBound方法里这样写:
            private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
            
    {
                Label label
    =(Label)(e.Item.FindControl("lblSex"));
                
    if(e.Item.Cells[0].Text=="0")
                
    {
                    label.Text
    ="";
                }

                
    if(e.Item.Cells[0].Text=="1")
                
    {
                    label.Text
    ="";
                }

            }
  • 相关阅读:
    大数据组件原理总结-Hadoop、Hbase、Kafka、Zookeeper、Spark
    淘宝搜索引擎的缓存机制入门总结
    Log4j写日志文件使用详解
    storm入门(一):storm编程框架与举例
    storm入门(二):关于storm中某一段时间内topN的计算入门
    关于京东推荐模型的阅读理解
    运维开发入门记录
    Redis 3.0.0 集群部署
    Redis集群部署
    秘籍
  • 原文地址:https://www.cnblogs.com/songafeng/p/124815.html
Copyright © 2011-2022 走看看