
June 23rd, 2001, 02:16 AM
|
|
Contributing User
|
|
Join Date: Dec 2002
Posts: 14,578
  
Time spent in forums: < 1 sec
Reputation Power: 22
|
|
|
Problem in Grid_Update
<i><b>Originally posted by : Spy++ (spy@usa.net)</b></i><br /><br />Hi,<br />I wrote the message "Grid.DataKeys problem". Well, forget that problem, I<br />discovered something new. In the Update event I have this code:<br /><br />string sValue1="";<br />string sValue2="";<br />TextBox Text1 = (TextBox)e.Item.FindControl("Text1");<br />TextBox Text2 = (TextBox)e.Item.FindControl("Text2");<br />sValue1=Text1 .Text;<br />sValue2=Text2 .Text;<br /><br />If I run the code, I got an error at line sValue1=Text1 .Text; saying<br />"Unable to dereference a null pointer". But if I debug and put a breakpoint<br />on that line, I can see that the textbox is found and the value is read!! So<br />why I get the exception. I managed to "fix" the problem in this way:<br /><br />string sValue1="";<br />string sValue2="";<br />TextBox Text1 = (TextBox)e.Item.FindControl("Text1");<br />TextBox Text2 = (TextBox)e.Item.FindControl("Text2");<br />if (Text1 !=null) sValue1=Text1 .Text;<br />if (Text2 !=null) sValue2=Text2 .Text;<br /><br /><br />Of course the are always found, so I can't see why I got the error if I<br />don't test if they are null!! Any solution or explanation? I don't like the<br />way I fixed it...<br /><br />And an other point: the value I get from the Text property is the old one,<br />the value before editing: why I don't get the current TextBox's value? Are<br />these problems related?<br />Please help...<br />Thank you<br /><br />
|