Datalist: update a datasource without using select/edit/update

H

Hartmut Schroth

Hi,

I need a solution for the following problem:

In the item template of a datalist control I have already
a button control with the commandname set to "select" to
perform some specific database action. I additionally want
to update an integer value in the underlying data source
by simply clicking an a check box or an imagebutton
WITHOUT USING THE EDIT/UPDATE COMMANDNAME property of the
datalist. So for example the datasource should be updated,
whenever the checkbox checked-property changes.

I tried two methods without success:

(1) If I use the OnCheckedChanged-event and set the
autopostback property to true, I cannot access the
SelectedIndex of the datalist in the event handler. But
this is the primary key of the datasource and is necesary
for the update. Accessing other objects of the item
template (e.g. a textbox which holds the primary key) is
not possible as well.

(2) I tried to use a second imagebutton instead of the
checkbox and set the commandname of the imagebutton
to "select" as well. Then everything is OK

with the SelectedIndex, but how can I determine, which of
the two different "Select" buttons has been clicked? I
need to know which one, because I have to perform
different tasks.

Thanks in advance.

Regards

Hartmut
 
J

Jacob Yang [MSFT]

Hi Hartmut,

Thank you for posting to the MSDN newsgroups.

I am interested in this issue. I am researching on it and will update you
as soon as possible.

Best regards,

Jacob Yang
Microsoft Online Partner Support
Get Secure! ¨C www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
J

Jacob Yang [MSFT]

Hi Hartmut,

Based on my research and experience, you can distinguish these buttons by
using the CommandArgument property. For example,

1. Assign the different values to the CommandArgument properties of the
button and imagebutton inside the datalist
2. Hook the ItemCommand event of the datalist control. this event fires
when a button inside the datalist was clicked and it also fires before the
SelectedIndexChanged event.
3. In the ItemCommand event, get the value of the CommandArgument property
via the e argument of the event. With the different value of the
CommandArgument property, you should know which button was clicked.
4. In the subsequent SelectedIndexChanged event you can do different things
according to the different CommandArgument

I hope it helps.

Best regards,

Jacob Yang
Microsoft Online Partner Support
Get Secure! ¨C www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
H

Hartmut Schroth

Hi Jacob,

thank you for yout cool hint. It solves my problem exactly.

Best regards

Hartmut Schroth
 

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

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top