2012-06-20 50 views
0

在我的PrinterPackage中。 ASPX文件我有以下'用戶控制'如何隱藏ASP.NET webform中的列

<%@ Register Src="~/ProvisionControls/DeferredTaxRollforwardControl.ascx" TagPrefix="uc9" TagName="DeferredTaxesRollforwardControl" %> 
    ... 
    ... 
<div> 
    <uc9:DeferredTaxesRollforwardControl ID="DeferredTaxesRollforwardControl1" runat="server" /> 
</div> 

它調用控制文件「DeferredTaxRollforwardControl。 ASCX'包含我的表定義如下:

<table style="width: 4600px; border-spacing:0px;" border="0" frame="hsides" cellpadding="2" cellspacing="1"> 

<tr id = "tblTempDiff"> //want to import this 


<td style="width:7.6%;" width="2px;" class="paintYellowTotalLeftBold"> 
    Grand Total Current 
</td> 
<td style="width:2.8%;" width="2px;" class="paintYellowTotalBold"> 
    <asp:Label ID="lblGrandTotalUnadjustedBeginningBalance" runat="server" Text=""></asp:Label> 
</td> 
... and more <td> 

我試圖顯示錶,也隱藏着一些使用下面的代碼在我PrinterPackage列。 aspx.cs文件:

TableRow row = DeferredTaxesRollforwardControl1.FindControl("tblTempDiff") as TableRow; 
     row.Cells[0].Visible = true; 
     row.Cells[1].Visible = true; 
     row.Cells[2].Visible = true; 
     row.Cells[3].Visible = true; 
     row.Cells[4].Visible = true; 
     row.Cells[5].Visible = true; 
     row.Cells[6].Visible = true; 
     row.Cells[7].Visible = true; 
     row.Cells[8].Visible = true; 
     row.Cells[9].Visible = false; 
     row.Cells[10].Visible = false; 
     row.Cells[11].Visible = false; 
     row.Cells[12].Visible = false; 

但是,這似乎並沒有拿起桌上行tblTempDiff並給了我一個空值來代替。我怎樣才能從TableRow tblTempDiff導入的數據,然後隱藏我想隱藏的任何列?

如果你需要更多的信息,請問我問題,因爲我知道我不是解釋我的問題的最佳人選。

回答

0

後面的代碼無法看到你創建的<tr>,因爲它不是一個服務器控件。在runat="server"屬性添加到<tr>

<tr id="tblTempDiff" runat="server"> 

而且使用System.Web.UI.HtmlControls.HtmlTableRow代替TableRow。兩件不同的事情。

+0

即使在包含runat =「server」後,它仍然不會填充我的TableRow'行'。任何其他方式我可以執行相同的事情?你能舉個例子嗎? – CarbonD1225

+0

它仍然爲空?還是細胞只是空的? – rikitikitik

+0

它仍然顯示我null作爲「行」的值,當我調試它。當它試圖執行visible = false時,它會給我一個空的異常。 – CarbonD1225

0

@ user1319424:不是已經創建表,而是使用佔位符,然後創建動態表並將該表綁定到佔位符。

請參考以下鏈接: http://www.dotnetcurry.com/ShowArticle.aspx?ID=135

+0

我不能更改現有的表格或創建新的動態表格,因爲我將功能添加到已存在的代碼中,並且不想重新創建已有的功能。任何其他方式,我可以做到這一點? – CarbonD1225

相關問題