Events of DataGrid child controls

Events of DataGrid child controls

Post by Scott M » Sun, 14 Nov 2004 09:14:24


How do you access the event handlers for controls in Template columns of a
DataGrid?
 
 
 

Events of DataGrid child controls

Post by Jos » Sun, 14 Nov 2004 21:22:59


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

 
 
 

Events of DataGrid child controls

Post by Scott M » Sun, 14 Nov 2004 23:24:49

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.
 
 
 

Events of DataGrid child controls

Post by Jos » Mon, 15 Nov 2004 02:27:47


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
 
 
 

Events of DataGrid child controls

Post by Scott M » Mon, 15 Nov 2004 03:18:11

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.
 
 
 

Events of DataGrid child controls

Post by v-schan » Tue, 16 Nov 2004 16:41:29

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

Events of DataGrid child controls

Post by Scott M » Tue, 16 Nov 2004 23:39:00

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.
 
 
 

Events of DataGrid child controls

Post by v-schan » Wed, 17 Nov 2004 10:45:39

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