wire up in events for C# newbie

J

jhcorey

I mentioned this recently in another post.

Let's say I want to use the ItemDataBound event for a datagrid.

I assume that I need:
this.DataGrid1.ItemDataBound += new
System.Web.UI.WebControls.DataGridItemEventHandler(this.DataGrid1_ItemDataBound);

in the InitializeComponent function. Is this correct, or is there
another way
to do this?

Because (1) the comments say not to touch this; and (2) this function
keeps getting cleared out, which I've noticed is a known problem.
I'm evidently carrying some habits over from vb.net that keep messing
me up.

TIA,
Jim
 
G

Guest

In Design View of your page, select the object you want to wire up events for
and open the Properties tab. On this tab you should see a lightning bolt.
Click the bolt and in here you can see all of the available events for your
selected object.

HTH
 
E

Eliyahu Goldin

Jim,

You can set the event handler in .aspx file as an attribute:

<asp:datagrid ... OnItemDataBound="DataGrid1_ItemDataBound" .. >

This format doesn't use the Design view and it doesn't get cleared out. You
will need to declare DataGrid1_ItemDataBound as protected.

Eliyahu
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top