2009-06-04 86 views
0

我有一個Gridview,我創建了一個連接到RowDataBound事件的動態頁腳。請參閱動態創建的GridView中的頁腳值VB VB

但有50/50的機會,其中3列沒有數據。

我希望能夠動態地隱藏沒有數據的列,如果可能的話。

我已經嘗試在RowDatabound事件中通過檢查值是否爲0但是不起作用,因爲我認爲事件被調用提前?

有沒有辦法在所有數據綁定後引用頁腳行中的值?

在VB

理想

`Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound 




    If e.Row.RowType = DataControlRowType.DataRow Then 
     TotalOffered += DataBinder.Eval(e.Row.DataItem, "Offered") 
     TotalHandled += DataBinder.Eval(e.Row.DataItem, "Handled") 
     TotalHandled30 += DataBinder.Eval(e.Row.DataItem, "Handled30") 
     TotalHandlingTime += (DataBinder.Eval(e.Row.DataItem, "AHT") * DataBinder.Eval(e.Row.DataItem, "Handled")) 
     TotalTalkTime += ((DataBinder.Eval(e.Row.DataItem, "AHT") * DataBinder.Eval(e.Row.DataItem, "Talk"))) * DataBinder.Eval(e.Row.DataItem, "Handled") 
     TotalHoldTime += ((DataBinder.Eval(e.Row.DataItem, "AHT") * DataBinder.Eval(e.Row.DataItem, "Hold"))) * DataBinder.Eval(e.Row.DataItem, "Handled") 
     TotalWrapTime += ((DataBinder.Eval(e.Row.DataItem, "AHT") * DataBinder.Eval(e.Row.DataItem, "Work"))) * DataBinder.Eval(e.Row.DataItem, "Handled") 

     ' If there is agent data calculate a running total 
     If IsDBNull(DataBinder.Eval(e.Row.DataItem, "Pri_Agent_Sign_in")) Then 
      GridView1.Columns(0).Visible = False 


     Else 
      TotalSignedin += DataBinder.Eval(e.Row.DataItem, "Pri_Agent_Sign_in") 
      TotalAvail += DataBinder.Eval(e.Row.DataItem, "Pri_Agent_Sign_in") * DataBinder.Eval(e.Row.DataItem, "Avail_Time") 
      TotalIdle += DataBinder.Eval(e.Row.DataItem, "Pri_Agent_Sign_in") * DataBinder.Eval(e.Row.DataItem, "Unavail_Time") 



     End If 

     ' If there is forecast data calculate a running total 

     If IsDBNull(DataBinder.Eval(e.Row.DataItem, "ORG_FOR_VOL")) Then 


     Else 
      TotalForecastVolume += DataBinder.Eval(e.Row.DataItem, "ORG_FOR_VOL") 
      TotalForecastAHT += DataBinder.Eval(e.Row.DataItem, "ORG_FOR_VOL") * DataBinder.Eval(e.Row.DataItem, "ORG_FOR_AHT") 
     End If 



    ElseIf e.Row.RowType = DataControlRowType.Footer Then 
     e.Row.Cells(0).Text = "Totals : " 
     e.Row.Cells(1).Text = TotalOffered.ToString 
     e.Row.Cells(2).Text = TotalHandled.ToString 
     e.Row.Cells(3).Text = TotalHandled30.ToString 
     e.Row.Cells(4).Text = (TotalHandled/TotalOffered).ToString("#0%") 
     e.Row.Cells(5).Text = (TotalHandled30/TotalHandled).ToString("#0%") 
     e.Row.Cells(6).Text = (TotalHandlingTime/TotalHandled).ToString("N0") 
     e.Row.Cells(7).Text = (TotalTalkTime/TotalHandlingTime).ToString("#0%") 
     e.Row.Cells(8).Text = (TotalHoldTime/TotalHandlingTime).ToString("#0%") 
     e.Row.Cells(9).Text = (TotalWrapTime/TotalHandlingTime).ToString("#0%") 


     ' If agent data then add total data to footer 
     If TotalSignedin = 0 Then 

     Else 

      e.Row.Cells(11).Text = (TotalAvail/TotalSignedin).ToString("#0%") 
      e.Row.Cells(12).Text = (TotalIdle/TotalSignedin).ToString("#0%") 
      e.Row.Cells(12).HorizontalAlign = HorizontalAlign.Center 

     End If 

     If TotalForecastVolume = 0 Then 

     Else 

      e.Row.Cells(13).Text = TotalForecastVolume.ToString 
      e.Row.Cells(14).Text = (TotalForecastAHT/TotalForecastVolume).ToString("F0") 

     End If 

    End If` 
+0

如果包含代碼可能會有幫助。 – Bryan 2009-06-04 19:04:53

+0

你還使用.net嗎?或只是asp? – Bryan 2009-06-04 19:09:59

+0

是的。發佈你的代碼。我敢肯定,我可以幫助.... – Eric 2009-06-04 19:29:54

回答

0

如果我正確理解你問,那麼你想要的代碼看起來應該是這樣的(我使用vb.net 2008年,最近的項目我有一個網格觀點的DataGridView如果您使用的aspx然後讓我知道,我會爲它生成一些代碼):

For i = 0 To DataGridView1.ColumnCount - 1 
     If DataGridView1.Rows(0).Cells(i).Value = "" Then 
      DataGridView1.Columns(i).Visible = False 
     End If 
    Next 

這當然是代號爲網格填充後。

這裏是你可以把你的GridView後您的aspx.vb文件中的代碼被完全加載:

For i = 0 To GridView1.Columns.Count - 1 
     If GridView1.FooterRow.Cells(i).Text = "" Then 
      GridView1.Columns(0).Visible = False 
     End If 
    Next 

如果你想爲你填充GridView中隱藏的列,那麼你將不得不忍受你的代碼。

0

在RowCreated中嘗試此操作。這是我的猜測,無法看到你的任何代碼。

Protected Sub GridView1_RowCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowCreated 
    If e.Row.RowType = DataControlRowType.Footer Then 
     If e.Row.Cells(0).Text = "" Then 
      GridView1.Columns(0).Visible = False 
     End If 
    End If 
End Sub