Grid View Display different columns between item/edit templates

G

Guest

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
 
G

Guest

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

Thanks
 
B

Bruno Alexandre

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"
 

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

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top