What I Learned Today – 30july2008

  • A LinkButton in ASP.Net has both an OnClick event and an OnCommand event.  The OnClick event expects your typical EventArgs, while the OnCommand event can receive CommandEventArgs.  I was about to go nuts trying to figure out how to convince my app to use CommandEventArgs in a regular OnClick event!  I was like “If I can use CommandName and CommandArgument in my LinkButton tag, HOW THE HELL am I supposed to get them fed into the click event!!?!?!”  Well, now I know.
  • If you’re using a GridView to display a list of items, you can use Container.DataItem.Index to display the items’ index in the collection.  It probably works with other things like DataGrid, etc.  You can also use it as an argument, thus: <asp:LinkButton … CommandArgument='<%# Container.DataItem.Index %>’ />  – remember that it’ll come across as a string or object in the argument, though.  Just do an int.Parse() or whatever.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: