INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Serializing a property

Serializing a property

(OP)
I have a GridViewRow that I am trying to serialize because I am taking the data from the row to use in a couple of other rows and I want the row to be accessible on postback.

I tried this but it doesn't work:

CODE

[Serializable]
        public GridViewRow GVR
        {
            get
            {
                return (GridViewRow)ViewState["GVR"];
            }
            set
            {
                //if (value == string.Empty) value = "7";
                ViewState["GVR"] = value;
            }
        } 

But the error I get is:

Attribute 'Serializable' is not valid on this declaration type. It is only valid on 'class, struct, enum, delegate' declarations.

How can I make a GridViewRow property serializable?

Thanks,

Tom

RE: Serializing a property

I don't see any reason that you need to serialize the data. Why do you think you need to?
Also, the error is telling you that that attribute is only valid on those types of objects

RE: Serializing a property

(OP)
Viewstate needs it to be serialized or you get an error.

I want to use a property and move it to and from the viewstate so it is there when I do a postback.

Thanks,

Tom

RE: Serializing a property

what is the error?

RE: Serializing a property

(OP)
If I don't have the serialization line, I get the following:

System.Runtime.Serialization.SerializationException: Type 'System.Web.UI.WebControls.GridViewRow' in Assembly 'System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' is not marked as serializable.

RE: Serializing a property

From the research I have done, it seems you can't serialize this type of object.
All responses seem to be to have a property for each cell in the gvr.
If you change it to a list of GVRs you may be able to serialize that, but I haven't tried that yet.

Can you explain in detail what exactly you are trying to do? there may be a better way to accomplish what you want to do than trying this

RE: Serializing a property

(OP)
The reason I do this is because if I press a button on my page, an event fires that allows you to get the information from the row the button was on.

But then I use the fields in the row for the ODS to use to get data from the database and fill a detail grid. But when the ODS is setting up the call to the stored procedure (ODS_ObjectCreteated) any private variables are gone so I usually do:

public string ETA
{
get
{
return (string)ViewState["ETA"];
}
set
{
ViewState["ETA"] = value;
}
}

But a GridViewRow needs to be serialized somehow. What I did to solve the issue was to get each piece of data I needed (such as the ETA) and stored those in the ViewState. I was hoping not to have to do that by storing the Gridviewrow and just get the data I needed later.

Thanks,

Tom

RE: Serializing a property

2 things here.
First a quick fix to your problem is you can use Session instead of viewstate. Kind of overkill but it works.

2. I would not get a gridview row's data to get other data. You should be using the DataKeys property of the gridview. Here you can specify a key or keys of that datatable. So, for example, you can say
columnname "ID" is your key value. On the select of that row, you can get that datakey's value and pass it to your query. Not sure of the structure of your table(s) but I think that is the best way to go.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close