onedit method

J

John H

I have a datagrid that is bound to a database table. One field in the table
is gender. When my datagrid first renders the Gender column shows "Male" or
"Female". When I click Edit the Gender column displays 2 radio buttons so
you can choose male or female.

The thing is, I want to ensure that the correct radio button is "checked"
depending on the database value.

I thought it would be easy to do this by adding some extra code into the
Datagrids EDIT method so that when the user clicks on the edit link, my edit
method could access the database and if the gender field is male the rbMale
radio button is checked else the rbFemale button.

However, I can't access controls that are held in the <EditItemTemplate>
section from the edit method. I can use the FindControl method to find
controls by their ID that are in the <ItemTemplate></ItemTemplate> tags but
I can't use it to access controls in the
<EditItemTemplate></EditItemTemplate> tags.

For example, I can find the label and thus the text that is in the
<ItemTemplate> section like this:
Label gender = (Label)e.Item.FindControl("lblGender");
string genderText = gender.Text;

If I try to access a control in the EditItemTemplate the same way, it can't
find it. It has no problem finding these values from my update method when
an update event is fired though.

It's as though when an edit event fires you can only access the controls in
the <ItemTemplate> section which is odd because the controls in the
<EditItemTemplate> are displayed on the screen.

I must be getting mixed up with the scope of the whole thing but I can't
figure it out.

Any ideas would be most welcome.

Thanks in advance

John
 
J

Joel Cade, MCSD

It may be easier using a radiobutton list, rather than individual radio
buttons. If you do this, then the edit command would only need to gain
access to the one control (using
CType(e.Item.Cells(iRadioCell).Control(0),
RadioButtonList).SelectedIndex).

Hope this helps!


Joel Cade, MCSD .Net, MCAD, MCP
Fig Tree Solutions, LLC
http://www.figtreesolutions.com
 
J

John H

It may be easier using a radiobutton list, rather than individual radio
buttons. If you do this, then the edit command would only need to gain
access to the one control (using
CType(e.Item.Cells(iRadioCell).Control(0),
RadioButtonList).SelectedIndex).
Hi Joel thanks for your reply.

I couldnt even access a textbox from <EditItemTemplate>.
 

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,767
Messages
2,569,571
Members
45,045
Latest member
DRCM

Latest Threads

Top