- <!--id用于綁定數據的標識,-->
- <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表示要傳遞的參數,多個(gè)參數用逗號分割開(kāi)-->
- <asp:HyperLinkField DataNavigateUrlFields="OperId,operName" DataNavigateUrlFormatString="OperatorEdit.aspx?OperId={0}&operName={1}"
- DataTextField="OperName" HeaderText="登錄名稱(chēng)" >
- <ItemStyle Width="100px" />
- </asp:HyperLinkField>
- <asp:BoundField HeaderText="真實(shí)名稱(chēng)" DataField="TrueName">
- <ItemStyle Width="100px" />
- </asp:BoundField>
- <asp:BoundField HeaderText="備注" DataField="OperMemo" />
- <asp:HyperLinkField HeaderText="授權" NavigateUrl="OperatorRole.aspx" Text="角色授權" 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]);
- ///獲取或設置用于篩選在 DataView 中查看哪些行的表達式。
- dv.RowFilter = "isdel=0";
-
- this.gvLog.DataSource = dv;
- this.gvLog.DataBind();
注1:DataView 使您能夠創(chuàng )建 DataTable 中所存儲的數據的不同視圖,這種功能通常用于數據綁定應用程序。使用 DataView,您可以使用不同排序順序顯示表中的數據,并且可以按行狀態(tài)或基于篩選器表達式來(lái)篩選數據。
注2:如果獲取不到GridView隱藏控件的值,則需要加入以下一段代碼
- ///該方法名稱(chēng)應該與你綁定的時(shí)間名稱(chēng)一致
- 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:如果我們要根據某個(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>";
- }
- }
本站僅提供存儲服務(wù),所有內容均由用戶(hù)發(fā)布,如發(fā)現有害或侵權內容,請
點(diǎn)擊舉報。