Events of DataGrid child controls

Discussion in 'ASP .Net Datagrid Control' started by Scott M., Nov 13, 2004.

  1. Scott M.

    Scott M. Guest

    How do you access the event handlers for controls in Template columns of a
    DataGrid?
    Scott M., Nov 13, 2004
    #1
    1. Advertising

  2. Scott M.

    Jos Guest

    Scott M. wrote:
    > How do you access the event handlers for controls in Template columns
    > of a DataGrid?


    Right click on the datagrid.
    Choose Edit Templates.
    Select the column and the template from the dropdown list (in Web Matrix) or
    select the column from the menu (in Visual Studio).
    Select the control.
    Modify its event handlers through the property panel.

    --

    Jos
    Jos, Nov 13, 2004
    #2
    1. Advertising

  3. Scott M.

    Scott M. Guest

    Huh? There is no property of a control in a template column of a DataGrid
    that has anything to do with an eventhandler. This is Web Form DataGrid.

    "Jos" <> wrote in message
    news:...
    > Scott M. wrote:
    >> How do you access the event handlers for controls in Template columns
    >> of a DataGrid?

    >
    > Right click on the datagrid.
    > Choose Edit Templates.
    > Select the column and the template from the dropdown list (in Web Matrix)
    > or
    > select the column from the menu (in Visual Studio).
    > Select the control.
    > Modify its event handlers through the property panel.
    >
    > --
    >
    > Jos
    >
    >
    Scott M., Nov 13, 2004
    #3
  4. Scott M.

    Jos Guest

    Scott M. wrote:
    > Huh? There is no property of a control in a template column of a
    > DataGrid that has anything to do with an eventhandler. This is Web
    > Form DataGrid.


    Yes, I had guessed that, and yes, you can set properties of controls
    in template columns.

    What is your editor?

    The instructions I gave are for Web Matrix and Visual Studio.

    --

    Jos
    Jos, Nov 13, 2004
    #4
  5. Scott M.

    Scott M. Guest

    I'm not asking how to set properties. I'm asking how to access the event
    handler of a control in a template column of a DataGrid.

    "Jos" <> wrote in message
    news:...
    > Scott M. wrote:
    >> Huh? There is no property of a control in a template column of a
    >> DataGrid that has anything to do with an eventhandler. This is Web
    >> Form DataGrid.

    >
    > Yes, I had guessed that, and yes, you can set properties of controls
    > in template columns.
    >
    > What is your editor?
    >
    > The instructions I gave are for Web Matrix and Visual Studio.
    >
    > --
    >
    > Jos
    >
    >
    Scott M., Nov 13, 2004
    #5
  6. Hi Scott,

    Thanks for posting. Not sure what you'd like to do on the sub control's
    eventhandler. But if you want to referenct it, we need to get the sub
    controls' control reference first. To do this, we can loop through the
    DataGrid.Items collection and use FindControl on each DataGridItem's
    certain Cell. For example:

    private void Button1_Click(object sender, System.EventArgs e)
    {
    foreach(DataGridItem item in this.dgMain.Items )
    {
    TextBox txt = item.Cells[0].FindControl("txtSub") as TextBox;
    //txt.TextChanged ....
    }
    }

    However, as I mentioned above, what do you want to do when get the
    reference of the control? If you want programly attach event handlers onto
    the controls, I think we'd better use the DataGrid's buildin "ItemCreated"
    or "ItemDataBound" event to do it, otherwise, there may occur some
    unexpected problems.
    Please feel free to let me know if you have any further questions or
    requriement. Thanks.

    Regards,

    Steven Cheng
    Microsoft Online Support

    Get Secure! www.microsoft.com/security
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)
    Steven Cheng[MSFT], Nov 15, 2004
    #6
  7. Scott M.

    Scott M. Guest

    Hi Steven,

    I want to add a checkbox to each row of a DataGrid in a Template column. and
    have users use these checkboxes as an alternate way to select a row in the
    grid (this way they can select multiple items in the grid).

    Of course, I need to be able to handle the CheckChanged event for each
    checkbox. I am familiar with FindControl, but what do I do once I've gotten
    a reference to the control.

    I'm using VB.NET, not C#.

    Thanks.


    "Steven Cheng[MSFT]" <> wrote in message
    news:...
    > Hi Scott,
    >
    > Thanks for posting. Not sure what you'd like to do on the sub control's
    > eventhandler. But if you want to referenct it, we need to get the sub
    > controls' control reference first. To do this, we can loop through the
    > DataGrid.Items collection and use FindControl on each DataGridItem's
    > certain Cell. For example:
    >
    > private void Button1_Click(object sender, System.EventArgs e)
    > {
    > foreach(DataGridItem item in this.dgMain.Items )
    > {
    > TextBox txt = item.Cells[0].FindControl("txtSub") as TextBox;
    > //txt.TextChanged ....
    > }
    > }
    >
    > However, as I mentioned above, what do you want to do when get the
    > reference of the control? If you want programly attach event handlers onto
    > the controls, I think we'd better use the DataGrid's buildin "ItemCreated"
    > or "ItemDataBound" event to do it, otherwise, there may occur some
    > unexpected problems.
    > Please feel free to let me know if you have any further questions or
    > requriement. Thanks.
    >
    > Regards,
    >
    > Steven Cheng
    > Microsoft Online Support
    >
    > Get Secure! www.microsoft.com/security
    > (This posting is provided "AS IS", with no warranties, and confers no
    > rights.)
    >
    Scott M., Nov 15, 2004
    #7
  8. Hi Scott,

    Thanks for your response. I've posted my reply and with a new VBNET version
    demo page in your another thread in the group. I'd appreciate if you have a
    look there. Also, if you feel convenient that we continue to followup in
    that thread, please feel free to post there. Thanks.

    Regards,

    Steven Cheng
    Microsoft Online Support

    Get Secure! www.microsoft.com/security
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)
    Steven Cheng[MSFT], Nov 16, 2004
    #8
    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. szabelin

    Events in DataGrid's child controls?

    szabelin, Jul 29, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    394
    szabelin
    Jul 29, 2003
  2. =?Utf-8?B?Z2xlbm4=?=

    Firing events for child controls in a DataGrid

    =?Utf-8?B?Z2xlbm4=?=, Jul 19, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    1,950
    =?Utf-8?B?Z2xlbm4=?=
    Jul 19, 2006
  3. Jeff Rodriguez
    Replies:
    23
    Views:
    1,083
    David Schwartz
    Dec 9, 2003
  4. Replies:
    0
    Views:
    193
  5. David Boike

    Child controls in Composite Controls not firing events

    David Boike, Aug 7, 2003, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    304
    David Boike
    Aug 7, 2003
Loading...

Share This Page