More GridView Problems

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I wanted better control over the display of the command buttons, so I
created Template columns for each command. (Otherwise the GridView was
putting extras spacing around the images and such.)

Is there a way to tell the GridView to only show certain columns if that
particular row is in edit mode? I can hide the Edit and Delete buttons when
entering edit mode, but when I display save and cancel buttons by enabling
their rowns, not surprisingly, I get save and cancel buttons on every row.

Thanks.

Jerry
 
Hi Jerry,

I think Brooke's suggestion is reasonable. For GridView or other template
databound control(DataGrid...), it's hard and not efficient to show/hide a
whole column. However, we can easily show/hide the sub webcontrols in the
GridView's certain column's Template(ItemTemlate or EditTemplate) according
to the databound value. So for your scenario, you can add a TemplateField
in the GridView and put the button and set them as visible in ItemTemplate
, but do not add the button or set them as invisible in EditTemplate. In
addition, if you need further customziation according to the databound at
runtime, you can register the gridview's RowDataBound event and perform
customization on the TemplateFields's control collection.

Hope this helps.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
If I understand what you're saying, then this still doesn't have the effect
that I need, although I did just learn something new about the templates,
etc. as a side effect to investigating what you said...

The issue now is that when there is a row in edit mode, the other items
still have their item template buttons showing. I don't want the user to be
able to click an edit button for row 5 when they are already in edit mode
for row 3. That's why I was hiding columns. So that all of the rows had
the edit buttons hidden when the user is in edit mode for a single row.
(The only row that should have any buttons is the row being edited.

Am I missing something that makes that easy without hiding columns? Thanks.

Jerry
 
Thanks for your further followup Jerry,

So what you want is make some certain button in the ItemTemplate not
visible or usable when there is a certain item in edit mode, correct? If
so, I'm afraid you have to use the GridView control's RowDataBound or
RowCreated event, in that event, you can get the reference to the certain
control (button ) you want to disable, and whether to disable it depend on
the current GridView's EditItemIndex, if it is in the valid range(that
means there is a certain item in edit mode), you will need to disable that
control in each item template row. How do you think of this?

Regards,

Steven Cheng
Microsoft Online Community Support


==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================


This posting is provided "AS IS" with no warranties, and confers no rights.
 

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

Back
Top