Need help on template columns in datagrid

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
 
G

Guest

Hi,

What's the AutoGenerateColumns value of your datagrid
Can you show your code

Bin Song, MCP
 
C

CW

AutoGenerateColumns is false.

I found a few articles from MSDN website, and now have got it working.

Thanks for the help.
 

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,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top