Dropdownlist doesn;t hold viewstate in templated datagrid column

R

Richard Myers

Hello

I have a datagrid that has a TemplatedColumn containing a dropdown list
(DDL). This DDL is filled for each datagrid row via the itemcreated created
event.

The first time i postback none of the selections made by the user are
available for each dropdownlist on the server. They all simply have values
equal to the first record of the datasource.... which is not very useful.

However after i have posted back once; on the postbacks that follow i have
access to the selections the user made?

The DDL is hooked up as per usual with runat=server and an ID value. Its not
that it cannot be seen by the server, i can interrogate its values via debug
tools, but they all just equal the value of the first record. This behaviour
is just plain weird as if something hasn't been registered with viewstate
but viewstate is enabled so what gives?

Richard
 
R

Richard Myers

Hi Eliyahu

Thanks for the reply. Im aware of the diffrence between the two events and
Ive chossen ItemCreated specifically.
I had tried ItemDataBound just for debugging purposes but it makes no
difference. Interesting though if i change the data source the problem goes
away.

That doesn't help me however as i need the original datasource but it might
give some further insight. What is strange however is that both datasources
are datatables and ultimately i fail to see how the data source could affect
it anyway, since once its been sent to the client the datasource is scoped
out.

Somethings clearly going on in viewstate but its such a simple page that i
fail to see what it could be? Ive tried pretty much everything i can think
of?

Thanks anyway
Richard
 
E

Eliyahu Goldin

Richard,

I can't explain the ddl behavior fully, but there is one thing that doesn't
look right. You should use ItemDataBound event rather than ItemCreated for
operations on each row. Try it first and see if the problem persists.

Eliyahu
 
R

Richard Myers

Actually i take that back about the separate data source working. It
doesn't. It (the page) still needs to be posted back to the server before
the Viewstate will wake up and maintain page state.

Richard
 
R

Richard Myers

O.k Thanks Eliyahu,

Ive sorted it out. Its wasn;t what you were suggesting but it was something
twice as stupid. I had left this line of code in my ItemCreated event

e.Item.ID = e.Item.ClientID

I was screwing around with something earlier and forgot to take it it out.
That would be why my viewstate was standing on its head.
Anyway all sorted now. Thanks for your help.

Richard
 
E

Eliyahu Goldin

Richard,

Check the logic in Page_Load. Ar you using IsPostBack property? Make sure
you are not re-populating the ddls on postbacks.

Eliyahu
 

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

Top