C
CW
In an earlier thread, I was asking for help on "Invalid attempt to
FieldCount when reader is closed" error when I was using a dataset rather
than a datareader to bind to a datagrid.
After playing around with it, I found out that the error was caused by
template columns. Once I remove template columns, everything worked fine.
Here are my scenarios and I would appreciate input on it.
My datagrid is bound to a orderlines table. In the edit mode, I want to
allow user to select product from a drop down list.
The steps I have followed are as follows:
(1) Turn the product model column into a template column.
(2) Edit this template column to include an unbound drop down box (called
DDLModelNumber) in the edit template mode. Originally I also had a drop down
box in the item template mode. However, this would cause the invalid field
count error when the form first loads.
(3) In the ItemCreated event, I would use
e.item.findcontrol("DDLModelNumber") to determine whether I am in edit mode.
If I am, then I would populate the drop down list, and then set its
SelectedIndex to the current selection.
(4) On update event, I would write the change back to the server by grabbing
the value from DDLModelNumber.
However, I found that I get this dreaded Invalid Field Count error after I
click edit on the datagrid (which would firstly populate the grid, as well
as the DDLModelNumber drop down box, and then attempt to DataBind). For some
reason, when calling databind method, if I have a drop down list in the
template, it causes this invalid field count error.
I would appreciate input on (1) how to get around this drop down list
conflict with databind operations and (2) whether the method I am using is
the best way to achieve the functionalities I am after.
Thanks in advance
FieldCount when reader is closed" error when I was using a dataset rather
than a datareader to bind to a datagrid.
After playing around with it, I found out that the error was caused by
template columns. Once I remove template columns, everything worked fine.
Here are my scenarios and I would appreciate input on it.
My datagrid is bound to a orderlines table. In the edit mode, I want to
allow user to select product from a drop down list.
The steps I have followed are as follows:
(1) Turn the product model column into a template column.
(2) Edit this template column to include an unbound drop down box (called
DDLModelNumber) in the edit template mode. Originally I also had a drop down
box in the item template mode. However, this would cause the invalid field
count error when the form first loads.
(3) In the ItemCreated event, I would use
e.item.findcontrol("DDLModelNumber") to determine whether I am in edit mode.
If I am, then I would populate the drop down list, and then set its
SelectedIndex to the current selection.
(4) On update event, I would write the change back to the server by grabbing
the value from DDLModelNumber.
However, I found that I get this dreaded Invalid Field Count error after I
click edit on the datagrid (which would firstly populate the grid, as well
as the DDLModelNumber drop down box, and then attempt to DataBind). For some
reason, when calling databind method, if I have a drop down list in the
template, it causes this invalid field count error.
I would appreciate input on (1) how to get around this drop down list
conflict with databind operations and (2) whether the method I am using is
the best way to achieve the functionalities I am after.
Thanks in advance