FormView update problem
am 02.04.2008 18:15:03 von 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
Re: FormView update problem
am 07.04.2008 19:43:25 von jphaycock
On 2 Apr, 17:15, "jphayc...@googlemail.com"
wrote:
> 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 =A0 int
> Name =A0 =A0string
> Description =A0 =A0string
> 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 =3D FormView2.FindControl("Id") as Label;
> =A0 =A0 =A0 =A0 if (skillID !=3D null)
> =A0 =A0 =A0 =A0 {
> =A0 =A0 =A0 =A0 =A0 =A0 e.NewValues["Id"] =3D skillID.Text;
> =A0 =A0 =A0 =A0 }
> =A0 =A0 =A0 =A0 else
> =A0 =A0 =A0 =A0 {
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0//get annoyed!!
> =A0 =A0 =A0 =A0 }
>
> 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 =3D (Label)FormView2.FindControl("IdLabel1");
string myID =3D labelID.Text;
if (myID !=3D null)
{
e.NewValues["Id"] =3D 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