在我的gridview中,我有以下的東西,如我在頁面加載中綁定sql和gridview所示,因爲我希望它在打開頁面時加載。如何從gridview中隱藏特定值(列)?
SqlConnection conn = new SqlConnection();
conn.ConnectionString = "Data Source = localhost; Initial Catalog = MajorProject; Integrated Security= SSPI";
conn.Open();
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter("SELECT memberreportid, typeofcrime, crdatetime, address, detail, incidentdate, incidenttime, property, victim, suspect from memberreport", conn);
da.Fill(ds);
GWCase.DataSource = ds;
GWCase.DataBind();
conn.Close();
但是,我試圖防止財產,受害者和嫌疑人列出現在gridview。我用
Visible = false;
在我的gridview,但它完全刪除我的gridview(當然)。
我試圖使用的BoundField如在我的GridView如下所示,並設置可見性爲假以專門設置的列的可見假然而,仍然被顯示
<asp:GridView ID="GWCase" runat="server" BackColor="#CCCCCC" BorderColor="#999999" BorderStyle="Solid" BorderWidth="3px" CellPadding="4" CellSpacing="2" ForeColor="Black" Width="100%" AutoGenerateSelectButton="True" OnSelectedIndexChanged="GWCase_SelectedIndexChanged">
<FooterStyle BackColor="#CCCCCC" />
<HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#CCCCCC" ForeColor="Black" HorizontalAlign="Left" />
<RowStyle BackColor="White" />
<SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#F1F1F1" />
<SortedAscendingHeaderStyle BackColor="#808080" />
<SortedDescendingCellStyle BackColor="#CAC9C9" />
<SortedDescendingHeaderStyle BackColor="#383838" />
<Columns>
<asp:BoundField DataField="property" HeaderText="property" SortExpression="property" Visible="false"/>
<asp:BoundField DataField="victim" HeaderText="victim" SortExpression="victim" Visible="false" />
<asp:BoundField DataField="suspect" HeaderText="suspect" SortExpression="suspect" Visible="false" />
</Columns>
</asp:GridView>
的列。我如何從gridview中刪除3列。請不要問我從我的sql語句中刪除3屬性,因爲我需要數據以實現更多功能。
我也試過這個方法我在這個thread發現SO
protected void GridView_RowDataBound(object sender, GridViewRowEventArgs e)
{
e.Row.Cells[7].Visible = false;
e.Row.Cells[8].Visible = false;
e.Row.Cells[9].Visible = false;
}
但它沒有工作,以及:/
問候。
還是一樣 –
@TeoChuenWeiBryan查看我的更新回答 – Ehsan
我將我的數據源和綁定放在我的page_load中。如果我將它粘貼到page_load中,我會得到這個錯誤'錯誤'System.EventArgs'不包含'Row'的定義,也沒有接受類型'System'的第一個參數的擴展方法'Row'。可以找到EventArgs'(你是否缺少使用指令或程序集引用?)' –