GridView控制項的應用

來源:互聯網
上載者:User
GridView控制項的運用: 
 

 <asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False"
            CellSpacing="1" Height="1px" PageSize="26" Width="500px" CssClass="txt" 
                        OnPageIndexChanging="GridView1_PageIndexChanging" 
                        OnRowDeleting="GridView1_RowDeleting" OnRowDataBound="GridView1_RowDataBound" 
                        onselectedindexchanged="GridView1_SelectedIndexChanged">
            <Columns>
                <asp:BoundField DataField="ID" HeaderText="ID" />
                <asp:BoundField DataField="title" HeaderText="新聞標題" />
                <asp:BoundField DataField="Type" HeaderText="新聞類別" />
                <asp:BoundField DataField="IssueDate" HeaderText="發布日期" />
                <asp:HyperLinkField HeaderText="編輯" Text="編輯" DataNavigateUrlFields="id" 

                  DataNavigateUrlFormatString="Edit.aspx?id={0}" Target="main" />
                <asp:CommandField ShowDeleteButton="True" />
            </Columns>
        </asp:GridView>

 
DataNavigateUrlFields="id" 是用於提交的欄位。
 
//如果要提交兩個欄位,則代碼如下:
//DataNavigateUrlFields="id,name"
//DataNavigateUrlFormatString ="Edit.aspx??id={0}&name={1}" 。
 
這樣在RE_HperLink.aspx檔案中 sql= "select * from sudents wherr id='"+request.querystring("id")+"'" 就能運行成功了。
 
 “Edit.aspx?id="{0}"〉這是url傳參的方法,把變數id的值傳到下一個頁面中,變數的名稱可以隨便起,只要你知道用了哪個名字就可以,因為,你在Edit.aspx裡id通過   string   questionID   =   Request.QueryString["id"];來擷取它.
 
當有多個頁面時,點擊下標頁面變化的代碼:
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView1.PageIndex = e.NewPageIndex;
        GridView1.DataBind();
    }
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.