FormView update problem

J

jphaycock

I've been trying to do this all day.

Sorry if the lingo isn't right but I think this is close:

I have a formview that is using an ObectDataSource to bind to a class
in my app_code folder. I have an update method in that class that
works fine. and I am using this as the formViews update method. There
are just 4 fields

ID int
Name string
Description string
added boolean

The ID is taken from a dropdownList (selectedValue). When I choose an
item from the dropdown the formview is populated. I can add and delete
items in the form view but when i do an update it complains that the
ID column is read only.

I have used this check in the ItemUpdating event to check the value of
the id and it is null

Label skillID = FormView2.FindControl("Id") as Label;
if (skillID != null)
{
e.NewValues["Id"] = skillID.Text;
}
else
{
//get annoyed!!
}

I have no idea why it is getting set to null.

Has anyone got any ideas? Any help is much appreciated I have Googled
it to death but got nowhere

John
 
J

jphaycock

I've been trying to do this all day.

Sorry if the lingo isn't right but I think this is close:

I have a formview that is using an ObectDataSource to bind to a class
in my app_code folder. I have an update method in that class that
works fine. and I am using this as the formViews update method. There
are just 4 fields

ID   int
Name    string
Description    string
added boolean

The ID is taken from a dropdownList (selectedValue). When I choose an
item from the dropdown the formview is populated. I can add and delete
items in the form view but when i do an update it complains that the
ID column is read only.

I have used this check in the ItemUpdating event to check the value of
the id and it is null

Label skillID = FormView2.FindControl("Id") as Label;
        if (skillID != null)
        {
            e.NewValues["Id"] = skillID.Text;
        }
        else
        {
               //get annoyed!!
        }

I have no idea why it is getting set to null.

Has anyone got any ideas? Any help is much appreciated I have Googled
it to death but got nowhere

John

Can anyone help me with this it's driving me nuts.

It was easier to use the old datagrids!!!

I have tried doing this in the FormView_ItemUpdating method:

Label labelID = (Label)FormView2.FindControl("IdLabel1");
string myID = labelID.Text;
if (myID != null)
{

e.NewValues["Id"] = Convert.ToInt32(myID);
}

but it wont perform the update it complains that the column Id is read
only. It should be read only shouldn't it? It's a primary key.

I have set the DataKeyNames propery to "Id" so I can't understand what
is going wrong.

Thanks in advance

John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top