2016-04-29 82 views
0

我試圖找出如何在itemCommand塊中設置ID變量,然後在PagePropertiesChanged塊中共享它。試圖找出如何共享變量之間.net代碼之間潛在

我在想這是否可行?

這裏是什麼,我試圖做一個簡單的例子,

Public Shared ID As Integer 

Private Sub DataListCategories_ItemCommand(source As Object, e As DataListCommandEventArgs) Handles DataListCategories.ItemCommand 

    If (e.CommandName.Equals("ClickCategory")) Then 

      ID = e.CommandArgument 

    End if 

End sub 

Private Sub ListViewGallery_PagePropertiesChanged(sender As Object, e As EventArgs) Handles ListViewGallery.PagePropertiesChanged 


    Me.ListViewGallery.DataSource = Dal.GetPhotographyByCategory(ID) 
     Me.ListViewGallery.DataBind() 

End Sub 
+0

你是什麼意思「共享變量之間的潛艇」? – Gabor

+0

您是否想要在回傳之間保持價值? –

回答

0

您似乎在嘗試後背上之間堅持一個共享變量的ID(在C#中靜態),但你必須瞭解ASP.NET中共享/靜態變量的性質。

這在Lifetime of ASP.NET Static Variable

覆蓋以及可以使用Session對象一樣堅持的ID:

Session("ID") = ID 

或者使用像一個ASP.NET隱藏字段

<asp:hiddenfield id="IDField" runat="server" value="0"/> 

像這樣設置:

IDField.Value = ID 
0

我對你在說什麼感到困惑。我想你是說在HTML中放置一個隱藏的字段,然後在代碼中使用findcontrol調用它?

難道不能以其他方式完成嗎?