Developing Matt

My Technical Journal

Gridview lessons I learnt 3: Access gridview items

leave a comment »

Do yourself a favor and change your gridview fields to templates….at least change most of them. It’s just easier to work with and keeps everything the same. Accessing your gridview items can be a pain if you don’t.
Without it being a template, you can get your field’s text with
GridView1.SelectedRow.Cells(10).Text
And yes, if you add a column before cell 10 you’ll have to change this number.

With your item being a template you can get your field’s text with
CType(GridView1.SelectedRow.FindControl(“txtsales”), TextBox).Text

This isn’t necessarily easier, but a template gives you more control…so you’re going to need to with most items anyway. Here’s how to access a button’s enabled property
CType(GridView1.SelectedRow.FindControl(“SubmitButton”), Button).Enabled

You don’t have access to the dataformatstring property like i discussed in this post, but you can set the Text property to a function that you return and format as you like ( format(##,##0.##) to get 12,000.21). We discussed how to do this in this post.

Advertisements

Written by matt

September 9, 2007 at 9:32 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: