0

たとえば、私が事業体->顧客を持っている場合、とを持っているとしcustomerIdましょcustomerNamecustomerType。runat = "server"にasp:HiddenVariablehdnCustomerを作成しました

顧客のビジネスエンティティの値(コードビハインド)をhdnCustomerにシリアル化する場合、どのようにすればよいですか?また、シリアル化されたら、どのように逆シリアル化できますか?

// Pseudo code

Collection<Customer> customerList = new Collection<Customer>();

customerList = BusinessAccess.GetCustomerList();

hdnCustomer = serialize and assign the value of 'customerList' to hdnCustomer;

...

...

// Later on a select index change of one of the drop down lists

ドロップダウンリストのイベントハンドラー内:

{

Collection<Customer> customerList = new Collection<Customer>();

customerList = deserialize the value from hdnCustomer

int a = Convert.ToInt32(ddlDropDown.SelectedValue);

foreach(a in customerList)

{

// Do something

}

}
4

2 に答える 2

0

.netはすでにそうするためのいくつかのクラスを提供していると思います。この例を見てください

于 2010-06-26T09:23:59.480 に答える
0

XmlSerializerを使用してXMLとの間でシリアル化できます。

http://support.microsoft.com/kb/815813

ただし、オブジェクトをViewState []コレクションに格納するだけの場合は、次のようになります。

ViewState["Customer"] = customerList;

それは同じことをします:ユーザーから隠されたページにシリアル化可能なオブジェクトを保存します:しかし、それは人間が読める形式にはなりません。

(編集:逆シリアル化するには、ViewState ["Customer"]の値を取得し、使用する前にnullをチェックします!)

編集2:ViewStateへのオブジェクトの保存に関する便利なリンク:

http://www.beansoftware.com/ASP.NET-Tutorials/ViewState-In-ASP.NET.aspx

お役に立てば幸いです。

于 2010-06-26T09:25:53.410 に答える