Developing Matt

My Technical Journal

Gridview lessons I learnt 2: dynamically set control name

leave a comment »

I didn’t end up using this, but thought it would be handy to have in this blog to reference later. Say, on your gridview you want to know which button is clicked. For instance, if a user clicks a button on the wrong row and you want to find out which row the button was clicked (the easier way to do this is edit the item template and edit item template’s visible properties with the gui).

  • ~Convert your field to a template field
  • ~Add a Command Argument that calls a function in your vb: CommandArgument='<%# getButtonId(“Approve”) %>’
  • ~Now your function can contain all the logic to increment the button value so it will match the row id.

Public Function getButtonId(ByVal buttonName as object)
iButtID += 1
Return buttonName & iButtID
End Function

Wade is a genius with the gridview. He helped me out with this one.

Advertisements

Written by matt

September 6, 2007 at 6:01 am

Posted in Asp.net

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s

%d bloggers like this: