Sunday, March 11, 2012

Validation within Gridview control?

The reason the update did not work is that you used the one-way databinding expression Eval. Replace that with Bind and the update should work just as it did with the BoundField

Aaaargh, that simple! Thanks webswapp, been scratching my head all day over that one but yeah, just changing it to Bind("Username") did the trick and it now validates and updates perfectly.

5 star answer there mate, cheers!


Why does it tell me:

The value '' of the ValueToCompare property of 'CompareValidator1' cannot be converted to type 'Integer'.

when I have this in my source..

<

asp:CompareValidatorID="CompareValidator1"ControlToValidate="UnitNumber"Type="Integer"runat="server"ErrorMessage="CompareValidator"></asp:CompareValidator><asp:TextBoxID="UnitNumber"runat="server"Text='<%#Bind("UnitNumber") %>'></asp:TextBox>

Because a null value in the UnitNumber field would display in a TextBox as an empty string which cannot be converted to an integer. (BTW, your code above does not show operator=DataTypeCheckor ControlToCompare="SomeOtherTextBox", how does it work?)


I guess that may be where I am going wrong. I thought "Type" was what type I wanted to validate my control against...

webswapp:

Because a null value in the UnitNumber field would display in a TextBox as an empty string which cannot be converted to an integer. (BTW, your code above does not show operator=DataTypeCheckor ControlToCompare="SomeOtherTextBox", how does it work?)


I guess that may be where I am going wrong. I thought "Type" was what type I wanted to validate my control against...

webswapp:

Because a null value in the UnitNumber field would display in a TextBox as an empty string which cannot be converted to an integer. (BTW, your code above does not show operator=DataTypeCheckor ControlToCompare="SomeOtherTextBox", how does it work?)


I guess that may be where I am going wrong. I thought "Type" was what type I wanted to validate my control against... Also, that field doesn't h

webswapp:

Because a null value in the UnitNumber field would display in a TextBox as an empty string which cannot be converted to an integer. (BTW, your code above does not show operator=DataTypeCheckor ControlToCompare="SomeOtherTextBox", how does it work?)


I guess that may be where I am going wrong. I thought "Type" was what type I wanted to validate my control against... Also, that field doesn't have a Null v

webswapp:

Because a null value in the UnitNumber field would display in a TextBox as an empty string which cannot be converted to an integer. (BTW, your code above does not show operator=DataTypeCheckor ControlToCompare="SomeOtherTextBox", how does it work?)


I guess that may be where I am going wrong. I thought "Type" was what type I wanted to validate my control against... Also, that field doesn't have a Null value..

webswapp:

Because a null value in the UnitNumber field would display in a TextBox as an empty string which cannot be converted to an integer. (BTW, your code above does not show operator=DataTypeCheckor ControlToCompare="SomeOtherTextBox", how does it work?)


Woa!! Why did that just post like 5 times.....

No comments:

Post a Comment