DetailsView能将某字段的Visible=false隐藏掉,但我想在DataBind前根据table中某字段的值来决定 隐藏的字段是否显示出来这功能能实现吗??最好能直接用asp.net,要是不能js也可以。麻烦各位了!!!

解决方案 »

  1.   

    当然可以实现,这是常规处理!!
    在DataBound事件中设置!
    你可以贴点你的代码
      

  2.   

    visible='<%# GetVisible(Eval(""))%>
    或DataBound设置findcontrol
      

  3.   


    能举个例子吗?<asp:BoundField DataField="type1" HeaderText="故障类别">
                        <HeaderStyle Wrap="False" Font-Bold="True" />
                    </asp:BoundField>
    <asp:BoundField DataField="e_place" HeaderText="设备所处位置" Visible="False">
                        <HeaderStyle Wrap="False" Font-Bold="True" />
                    </asp:BoundField>
     <asp:BoundField DataField="e_name" HeaderText="设备名称" Visible="False">
                        <HeaderStyle Wrap="False" Font-Bold="True" />
                    </asp:BoundField>这是detailsView一部分代码,因为某些故障不是硬件设备,所以就不存在设备名称,位置等了,要是都显示出来detailsView会太大,效果不好,所以希望通过判定其中某字段type为硬件时,就显示设备名称和位置这两行出来。麻烦说一下DataBound事件要怎么写!!谢谢了
      

  4.   

    将 故障类别,设备所处位置 与 设备名称 字段转换成模板列
    在DataBound 中绑定每一行地数据时 用findcontrol 根据ID 找出 故障类别 判断是否显示
      

  5.   

    如果type是第二行,设备所处位置,设备名称分别是第3,第4行,则:
         protected void DetailsView1_DataBound(object sender, EventArgs e)
        {
            if (DetailsView1.Rows[1].Cells[1].Text == "硬件")
            {
                DetailsView1.Rows[2].Visible = false;
                DetailsView1.Rows[3].Visible= false;
            }
        }