locked
How to hide TemplateColumn from custom FieldTemplateUserControl? RRS feed

  • Question

  • User188291263 posted

    I have a custom FieldTemplateUserControl,and on certain values i want to hide row.

    Im doing this.Parent.Parent.Parent = false to get DetailsViewRow.

    Any better idea?

    Thanks

    Sunday, August 31, 2008 3:15 PM

All replies

  • User660823006 posted

    I would need more detail then what you have provided and exactly what you are tryingt to do. A better choice would be to write an IAutoFieldGenerator which is how a DetailsView control in Dynamic Data determines which fields are shown and what controls are created to display/edit those fields. You can read more about it: http://csharpbits.notaclue.net/2008/05/dynamicdata-generate-columnsrows-using.html. You could write one of these and based on the item you editing it can show as many or as few fields as you want.

    Monday, September 1, 2008 4:51 PM
  • User188291263 posted

     Hi Scott,i did read that article,basically i have my custom field Updated Date,
    in there,im checking if UpdatedDate == DateTime.MinValue and if it is i do hide row.

    IAutoFieldGenerator is returning fields whatever i want to show/hide,
    but how in public ICollection GenerateFields i can access a value of field to disable it?
    Is it i only have access to MetaColumn?


    Monday, September 1, 2008 5:07 PM
  • User-330204900 posted

    I'm asuming you want to hide the whole row when you find specific values in your field template control?

    Does the FiledTemplate controls do anything else?

    I would use the OnRowDataBound event or OnDataBound event to hide the ROW provided that the column name is known.

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    protected void GridView1_DataBound(object sender, EventArgs e)

    Hope this helps [:D]

    Monday, September 1, 2008 5:19 PM
  • User660823006 posted

    The IAutoFieldGenerator would be used to hide the row when looking at the Entity as a whole. If you want the FieldTemplate to hide it would need to do what you are currently doing but your FieldTempalte would fail in edit mode if it was not in a DetailsView.

    Monday, September 1, 2008 5:23 PM
  • User188291263 posted

    But on both those events i have to check field value,
    is it easier to control from FieldTemplateUserControl??
    My solution works perferct using Parent.Parent, but its kind of ugly.

    Monday, September 1, 2008 5:24 PM
  • User1641955678 posted

    I think there is some slight confusion in this thread between hiding a column (which the subject line refers to), and hiding a row (which it looks like is what you meant).  IAutoFieldGenerator won't help you to hide a row.  I can't think of a great way of doing it from the field template, because the same field templates are used in DetailsView, GridView, FormView and ListView.  I suppose there could be some support in the field template to let whatever container it's in that the current data item should not be displayed.  In the case of a DetailsView which only show one item, I guess it wouldn't display anything.

    David

    Tuesday, September 2, 2008 1:52 AM