Hide/Show EditCommandColumn In DataGrid

R

RN1

A Form has a few fields along with a Submit button & a DataGrid. The
fields & the Submit Button are encapsulated in a Panel named
pnlDataEntry & the DataGrid is encapsulated in a Panel named
pnlShowData. There is also a Session variable which comes from the
login page. If the user logs in as admin, then the session variable is
1 else 0. This is the code:

---------------------------------
Sub Page_Load(ByVal obj As Object, ByVal ea As EventArgs)
If Not (Page.IsPostBack) Then
Dim sessAdmin As Integer

sessAdmin = Session("Admin")

If (sessAdmin = 0) Then
pnlDataEntry.Visible = True
pnlShowData.Visible = False
Else
pnlShowData.Visible = True
Call LoadData()
End If
Else
pnlDataEntry.Visible = False
pnlShowData.Visible = True
Call LoadData()
End If
End Sub

Sub Submit(ByVal obj As Object, ByVal ea As EventArgs)
Dim dtEnd As DateTime
Dim dtStart As DateTime

pnlDataEntry.Visible = False
pnlShowData.Visible = True

dtStart = ............
dtEnd = .............

If (CDate(dtEnd) < CDate(dtStart)) Then
Response.Write("END TIME CANNOT PRECEDE START TIME!")
Else
Call InsertData(dtStart, dtEnd)
Call LoadData()
End If
End Sub

Sub InsertData(ByVal StartDate As DateTime, ByVal EndDate As DateTime)
'inserting data in the database
End Sub

Sub LoadData()
'binding data from the database to the DataGrid
End Sub

<form runat="server">
<asp:panel ID="pnlDataEntry" runat="server">
......................
......................
</asp:panel>

<asp:panel ID="pnlShowData" runat="server">
<asp:DataGrid ID="dgETS"..............runat="server">
<Columns>
<asp:BoundColumn............../>
<asp:BoundColumn............../>
<asp:BoundColumn............../>
<asp:BoundColumn............../>
<asp:EditCommandColumn CancelText="CANCEL" EditText="EDIT"
HeaderText="EDIT" UpdateText="UPDATE"/>
</Columns>
</asp:DataGrid>
</asp:panel>
</form>
---------------------------------

What I want is if the user logs in as admin i.e. sessAdmin=1, then
only should the DataGrid display the EditCommandColumn in the DataGrid
else the EditCommandColumn should remain hidden. Also the last 2
BoundColumns should be visible only if the user logs in as admin else
they should not be visible.

How do I do this?
 

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,982
Messages
2,570,190
Members
46,740
Latest member
AdolphBig6

Latest Threads

Top