iT邦幫忙

0

ASP 程式碼 把零隱藏

  • 分享至 

  • xImage

HI 各位大大:

小弟我碰到一個問題,就是要把以下表格裡面的零隱藏 想請問要怎麼做隱藏http://ithelp.ithome.com.tw/upload/images/20170410/200547734wuItC6cxs.png

以下是程式碼

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" BackColor="White" BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" CellPadding="3" ForeColor="Black" GridLines="Vertical" Height="21px" Width="845px" AllowPaging="True" PageSize="15" EnableModelValidation="True">
                <FooterStyle BackColor="#CCCCCC" />
                <SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
                <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
                <HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" Height="0px" Font-Size="Small" />
                <AlternatingRowStyle BackColor="#CCCCCC" />
                <Columns>
                    <asp:BoundField DataField="員工編號" HeaderText="員工編號" SortExpression="員工編號" >
                        <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                    </asp:BoundField>
                    <asp:BoundField DataField="員工姓名" HeaderText="員工姓名" SortExpression="員工姓名" >
                        <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                    </asp:BoundField>
                    <asp:BoundField DataField="年度特休" HeaderText="年度特休" SortExpression="年度特休" >
                        <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                    </asp:BoundField>
                    <asp:BoundField DataField="系統剩餘特休" HeaderText="系統剩餘特休" SortExpression="系統剩餘特休" >
                        <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                    </asp:BoundField>
                    <asp:BoundField DataField="1月" HeaderText="一月" SortExpression="1月" >
                        <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                    </asp:BoundField>
                    <asp:BoundField DataField="2月" HeaderText="二月" SortExpression="2月" >
                        <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                    </asp:BoundField>
                    <asp:BoundField DataField="3月" HeaderText="三月" SortExpression="3月" >
                        <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                    </asp:BoundField>
                    <asp:BoundField DataField="4月" HeaderText="四月" SortExpression="4月" >
                        <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                    </asp:BoundField>
                    <asp:BoundField DataField="5月" HeaderText="五月" SortExpression="5月" >
                        <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                    </asp:BoundField>
                    <asp:BoundField DataField="6月" HeaderText="六月" SortExpression="6月" >
                        <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                    </asp:BoundField>
                    <asp:BoundField DataField="7月" HeaderText="七月" SortExpression="7月" >
                        <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                    </asp:BoundField>
                    <asp:BoundField DataField="8月" HeaderText="八月" SortExpression="8月" >
                        <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                    </asp:BoundField>
                    <asp:BoundField DataField="9月" HeaderText="九月" SortExpression="9月" >
                        <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                    </asp:BoundField>                    
                    <asp:BoundField DataField="10月" HeaderText="十月" SortExpression="10月" >
                        <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                    </asp:BoundField>
                    <asp:BoundField DataField="11月" HeaderText="十一月" SortExpression="11月" >
                        <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                    </asp:BoundField>
                    <asp:BoundField DataField="12月" HeaderText="十二月" SortExpression="12月" >
                        <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                    </asp:BoundField>
                    <asp:BoundField DataField="剩餘特休" HeaderText="剩餘特休" SortExpression="剩餘特休" >
                        <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                    </asp:BoundField>
                    <asp:BoundField DataField="預扣尚未結案特休假單" HeaderText="預扣尚未結案特休假單" SortExpression="預扣尚未結案特休假單" >
                        <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                    </asp:BoundField>
                </Columns>
                <RowStyle HorizontalAlign="Center" VerticalAlign="Middle"  Font-Size="Small"/>
            </asp:GridView>

以上的程式碼有寫的不好也可以給點意見  我是剛學程式設計的新人

感謝

圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 個回答

0
海綿寶寶
iT邦大神 1 級 ‧ 2017-04-10 18:17:53
最佳解答
Put the code just after gridview1.databind() method.

Oitem represents the gridview row not a single column. Let reason is the first cell,Remarks is the second cell of your gridview then code looks like:

foreach (GridViewRow oItem in yourgridviewname.Rows)
{
if (oItem.Cells[0].Text == "0")
{
oItem.Cells[0].Text="";
}

if (oItem.Cells[1].Text == "0")
{
oItem.Cells[1].Text="";
}

}

資料來源

請問這一大段是要加在那裡呢??

在 GridView1.databind() 之後

大大我加在後GridView1.databind()後面好像不太對是那裡有問題呢??

Sub LoadData(ByVal pSql As String)

    Dim lcReturn As String
    Dim loSysLib As New SysLib
    Dim loDS As New DataSet

    lcReturn = loSysLib.GetDataSet(pSql, loDS, "TN_ABSENCE")

    If lcReturn = "" Then
        If (loDS.Tables(0).Rows.Count <>) Then

            GridView1.DataSource = loDS.Tables(0)
            GridView1.DataBind()
			
			
        Else
            GridView1.DataSource = loDS.Tables(0)
            GridView1.DataBind()

我要發表回答

立即登入回答