onedit method

Discussion in 'ASP .Net Datagrid Control' started by John H, Sep 27, 2004.

  1. John H

    John H Guest

    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
     
    John H, Sep 27, 2004
    #1
    1. Advertising

  2. 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

    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
     
    Joel Cade, MCSD, Sep 27, 2004
    #2
    1. Advertising

  3. John H

    John H Guest

    <Joel Cade>; "MCSD" <> wrote in message
    news:...
    > 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>.
     
    John H, Sep 27, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. jerry051
    Replies:
    2
    Views:
    774
    Oliver Sturm
    Aug 2, 2005
  2. Mike Wilmot
    Replies:
    0
    Views:
    3,304
    Mike Wilmot
    Dec 15, 2003
  3. CW
    Replies:
    0
    Views:
    574
  4. Carlos Oliveira
    Replies:
    0
    Views:
    19,007
    Carlos Oliveira
    Aug 19, 2004
  5. Kyung won Cheon
    Replies:
    0
    Views:
    213
    Kyung won Cheon
    Nov 21, 2008
Loading...

Share This Page