Hide/Show EditCommandColumn In DataGrid

  • Thread starter Thread starter RN1
  • Start date Start date
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?
 
Back
Top