Posts Tagged ‘LearnedToday’

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.