Grid View Display different columns between item/edit templates

Discussion in 'ASP .Net' started by =?Utf-8?B?Z2FuZQ==?=, Feb 16, 2007.

  1. Hi,

    In a gridview, How can i display different columns between item and edit
    modes.
    For eg. i have a sql that returns productname, categoryname, etc.
    In viewmode, i need to display only productname column and not categoryname
    column. Again in Edit mode, i need display/edit category name only. But not
    productname column shouldnt be displayed/editable.

    In visual studio 2005, I tried converting the columns to template fields and
    removed the field label/textboxes in item and edit templates.
    But the column exits with the header.

    How can i show/hide differnt columns between view/edit modes?
    can it be done using visual studio 2005 designer mode?

    Any help appreciated.

    Thanks
    Gane
    =?Utf-8?B?Z2FuZQ==?=, Feb 16, 2007
    #1
    1. Advertising

  2. I figured out by setting visible false for the field in GridView1_RowEditing
    method.

    Thanks

    "gane" wrote:

    > Hi,
    >
    > In a gridview, How can i display different columns between item and edit
    > modes.
    > For eg. i have a sql that returns productname, categoryname, etc.
    > In viewmode, i need to display only productname column and not categoryname
    > column. Again in Edit mode, i need display/edit category name only. But not
    > productname column shouldnt be displayed/editable.
    >
    > In visual studio 2005, I tried converting the columns to template fields and
    > removed the field label/textboxes in item and edit templates.
    > But the column exits with the header.
    >
    > How can i show/hide differnt columns between view/edit modes?
    > can it be done using visual studio 2005 designer mode?
    >
    > Any help appreciated.
    >
    > Thanks
    > Gane
    =?Utf-8?B?Z2FuZQ==?=, Feb 16, 2007
    #2
    1. Advertising

  3. No, you can't do that from Designer mode, designer mode has only the simple
    tasks, for what you want to accomplish you need to use the code mode.

    create an event onRowDataBound for that GridView

    now all you need to do is Hide the cells number that you want

    [let's imagine that you have 3 rows, and for normal view you need the 1st
    and the 2nd to show, to edit you need the 1st and the 3rd]

    Protected Sub gv_RowDataBound(ByVal sender As Object, ByVal e As
    System.Web.UI.WebControls.GridViewRowEventArgs) Handles gv.RowDataBound
    If e.Row.RowState = DataControlRowState.Normal Or e.Row.RowState =
    DataControlRowState.Alternate Then
    e.Row.Cells(0).Visible = True
    e.Row.Cells(1).Visible = True
    e.Row.Cells(2).Visible = False
    ElseIf e.Row.RowState = DataControlRowState.Normal Then
    e.Row.Cells(0).Visible = True
    e.Row.Cells(1).Visible = False
    e.Row.Cells(2).Visible = True
    End If
    End Sub

    and that's it. easy right?
    --

    Bruno Alexandre
    Strøby, Danmark

    "a Portuguese in Denmark"


    "gane" <> wrote in message
    news:...
    > Hi,
    >
    > In a gridview, How can i display different columns between item and edit
    > modes.
    > For eg. i have a sql that returns productname, categoryname, etc.
    > In viewmode, i need to display only productname column and not
    > categoryname
    > column. Again in Edit mode, i need display/edit category name only. But
    > not
    > productname column shouldnt be displayed/editable.
    >
    > In visual studio 2005, I tried converting the columns to template fields
    > and
    > removed the field label/textboxes in item and edit templates.
    > But the column exits with the header.
    >
    > How can i show/hide differnt columns between view/edit modes?
    > can it be done using visual studio 2005 designer mode?
    >
    > Any help appreciated.
    >
    > Thanks
    > Gane
    Bruno Alexandre, Feb 16, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Bazza Formez
    Replies:
    9
    Views:
    475
    Bazza Formez
    Dec 9, 2004
  2. Luqman
    Replies:
    2
    Views:
    3,789
    Luqman
    Feb 1, 2006
  3. JKop
    Replies:
    3
    Views:
    451
  4. recover
    Replies:
    2
    Views:
    784
    recover
    Jul 25, 2006
  5. Ann
    Replies:
    0
    Views:
    140
Loading...

Share This Page