GridView 建立以及後端如何取得資料 如何取得隱藏值

<asp:GridView runat="server" ID="GrvMap" AutoGenerateColumns="False" BackColor="White" BorderColor="#CCCCCC"

                BorderStyle="None" BorderWidth="1px" CellPadding="3" EnableModelValidation="True" OnRowDeleting="GrvMap_RowDeleting">

                <Columns>

                    <%-- 各種Columns... --%>

                    <asp:BoundField DataField="UserCompID" />

                    <asp:TemplateField HeaderText="刪除">

                        <ItemTemplate>

                            <asp:Button runat="server" Text="刪除" OnClientClick="return confirm('確定刪除?')" CommandName="Delete" />

                        </ItemTemplate>

                    </asp:TemplateField>

                </Columns>

                <FooterStyle BackColor="White" ForeColor="#000066" />

                <HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" />

                <PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left" />

                <RowStyle ForeColor="#000066" />

                <SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />

            </asp:GridView> 


下方的Style的部分是用html前端可以直接用按鍵設計


如果要隱藏第一條 不能直接在前端下Visible

要從後端下

GrvMap.Columns[0].Visible = false;

至於如果要重新讀取之後,繼續獲得資料,則需要先使Visible變成true 在取得資料之後再變成false

protected void GetLeaveMap()

    {

        GrvMap.Columns[0].Visible = true;

        // do something ...

        GrvMap.Columns[0].Visible = false;

    }

protected void GrvMap_RowDeleting(object sender, GridViewDeleteEventArgs e)

    {

        //取得資料

        //使用Grv的RowDelete 並且使用其內建的CommandName 函式 就能取得RowIndex

        string UserCompID = (GrvMap.Rows[e.RowIndex].Cells[0].Text == "&nbsp;") ? "" : GrvMap.Rows[e.RowIndex].Cells[0].Text;

       

        //  doSomething...

    }





留言

這個網誌中的熱門文章

無法載入檔案或組件 'System.IO.Compression' 或其相依性的其中之一。

MongoDB 入門

javascript 更改屬性及創建標籤