- <!--id用于綁定數(shù)據(jù)的標(biāo)識(shí),-->
- <asp:GridView ID="gvLog" runat="server" AutoGenerateColumns="False" CellPadding="3" CellSpacing="1"
- Width="100%" BackColor="#F3F3F3" BorderWidth="0px" OnRowDeleting="gvLog_RowDeleting" OnRowDataBound="gvLog_RowDataBound">
- <RowStyle BackColor="White" />
- <Columns>
- <!--綁定列-->
- <asp:BoundField DataField="OperId" >
- <ItemStyle CssClass="display:none;" />
- </asp:BoundField>
- <asp:BoundField HeaderText="No">
- <ItemStyle Width="30px" HorizontalAlign="Center" />
- </asp:BoundField>
- <!--帶鏈接的綁定列,DataNavigateUrlFields表示要傳遞的參數(shù),多個(gè)參數(shù)用逗號(hào)分割開(kāi)-->
- <asp:HyperLinkField DataNavigateUrlFields="OperId,operName" DataNavigateUrlFormatString="OperatorEdit.aspx?OperId={0}&operName={1}"
- DataTextField="OperName" HeaderText="登錄名稱" >
- <ItemStyle Width="100px" />
- </asp:HyperLinkField>
- <asp:BoundField HeaderText="真實(shí)名稱" DataField="TrueName">
- <ItemStyle Width="100px" />
- </asp:BoundField>
- <asp:BoundField HeaderText="備注" DataField="OperMemo" />
- <asp:HyperLinkField HeaderText="授權(quán)" NavigateUrl="OperatorRole.aspx" Text="角色授權(quán)" DataNavigateUrlFields="OperId" DataNavigateUrlFormatString="OperatorRole.aspx?operId={0}">
- <ItemStyle Width="60px" HorizontalAlign="Center" />
- </asp:HyperLinkField>
- <!--事件綁定操作,該例子是刪除時(shí)間-->
- <asp:CommandField HeaderText="操作" ShowDeleteButton="True">
- <ItemStyle Width="40px" HorizontalAlign="Center" />
- </asp:CommandField>
- </Columns>
- <SelectedRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" />
- <!--表格頭部樣式-->
- <HeaderStyle BackColor="#CCCCCC" Font-Bold="True" ForeColor="#FFFEEE" Height="15px" />
- <!--隔行變色-->
- <AlternatingRowStyle BackColor="#F9F9F9" />
- </asp:GridView>
- DataSet ds = operServices.GetList("");
- DataView dv = new DataView(ds.Tables[0]);
- ///獲取或設(shè)置用于篩選在 DataView 中查看哪些行的表達(dá)式。
- dv.RowFilter = "isdel=0";
-
- this.gvLog.DataSource = dv;
- this.gvLog.DataBind();
注1:DataView 使您能夠創(chuàng)建 DataTable 中所存儲(chǔ)的數(shù)據(jù)的不同視圖,這種功能通常用于數(shù)據(jù)綁定應(yīng)用程序。使用 DataView,您可以使用不同排序順序顯示表中的數(shù)據(jù),并且可以按行狀態(tài)或基于篩選器表達(dá)式來(lái)篩選數(shù)據(jù)。
注2:如果獲取不到GridView隱藏控件的值,則需要加入以下一段代碼
- ///該方法名稱應(yīng)該與你綁定的時(shí)間名稱一致
- protected void gvLog_RowDataBound(object sender, GridViewRowEventArgs e)
- {
- if (e.Row.RowType == DataControlRowType.DataRow || e.Row.RowType == DataControlRowType.Header)
- {
- ///指定隱藏列,并賦值
- e.Row.Cells[0].Visible = false;
- e.Row.Cells[1].Visible = false;
- }
- }
注3:如果我們要根據(jù)某個(gè)條件去改變表格某個(gè)值的樣式,可以在行綁定時(shí)間方法中加入如下代碼,如:
- protected void gvLog_RowDataBound(object sender, GridViewRowEventArgs e)
- {
- if (e.Row.RowIndex != -1)
- {
- if (Convert.ToInt16(e.Row.Cells[1].Text.ToString()) == 1)
- {
- e.Row.Cells[6].Text = "<font color='red'><b>" + e.Row.Cells[6].Text.ToString() + "</b></font>";
- }
- }
本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)
點(diǎn)擊舉報(bào)。