Groups | Blog | Home
all groups > asp.net datagrid control > november 2004 >

asp.net datagrid control : Events of DataGrid child controls


Scott M.
11/12/2004 7:14:24 PM
How do you access the event handlers for controls in Template columns of a
DataGrid?

Scott M.
11/13/2004 9:24:49 AM
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.

[quoted text, click to view]

Scott M.
11/13/2004 1:18:11 PM
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.

[quoted text, click to view]

Jos
11/13/2004 1:22:59 PM
[quoted text, click to view]

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
11/13/2004 6:27:47 PM
[quoted text, click to view]

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

v-schang NO[at]SPAM online.microsoft.com
11/15/2004 7:41:29 AM
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.
11/15/2004 9:39:00 AM
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.


[quoted text, click to view]

v-schang NO[at]SPAM online.microsoft.com
11/16/2004 1:45:39 AM
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.)
AddThis Social Bookmark Button