467,225 Members | 1,353 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,225 developers. It's quick & easy.

Grid View Display different columns between item/edit templates

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
Feb 16 '07 #1
  • viewed: 6925
Share:
2 Replies
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
Feb 16 '07 #2
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" <ga**@discussions.microsoft.comwrote in message
news:CA**********************************@microsof t.com...
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

Feb 16 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Filippo Pandiani | last post: by
3 posts views Thread by Simon Harris | last post: by
3 posts views Thread by Kenneth P | last post: by
1 post views Thread by Mad Scientist Jr | last post: by
2 posts views Thread by Joe Griffith | last post: by
117 posts views Thread by phil-news-nospam@ipal.net | last post: by
2 posts views Thread by Valli | last post: by
reply views Thread by Adict | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.