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.IsPostBac k) Then
Dim sessAdmin As Integer
sessAdmin = Session("Admin" )
If (sessAdmin = 0) Then
pnlDataEntry.Vi sible = True
pnlShowData.Vis ible = False
Else
pnlShowData.Vis ible = True
Call LoadData()
End If
Else
pnlDataEntry.Vi sible = False
pnlShowData.Vis ible = 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.Vi sible = False
pnlShowData.Vis ible = True
dtStart = ............
dtEnd = .............
If (CDate(dtEnd) < CDate(dtStart)) Then
Response.Write( "END TIME CANNOT PRECEDE START TIME!")
Else
Call InsertData(dtSt art, dtEnd)
Call LoadData()
End If
End Sub
Sub InsertData(ByVa l 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="pnlDataEntr y" runat="server">
............... .......
............... .......
</asp:Panel>
<asp:Panel ID="pnlShowData " runat="server">
<asp:DataGrid ID="dgETS"..... .........runat= "server">
<Columns>
<asp:BoundColum n............../>
<asp:BoundColum n............../>
<asp:BoundColum n............../>
<asp:BoundColum n............../>
<asp:EditComman dColumn CancelText="CAN CEL" EditText="EDIT"
HeaderText="EDI T" UpdateText="UPD ATE"/>
</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 EditCommandColu mn in the DataGrid
else the EditCommandColu mn 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?
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.IsPostBac k) Then
Dim sessAdmin As Integer
sessAdmin = Session("Admin" )
If (sessAdmin = 0) Then
pnlDataEntry.Vi sible = True
pnlShowData.Vis ible = False
Else
pnlShowData.Vis ible = True
Call LoadData()
End If
Else
pnlDataEntry.Vi sible = False
pnlShowData.Vis ible = 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.Vi sible = False
pnlShowData.Vis ible = True
dtStart = ............
dtEnd = .............
If (CDate(dtEnd) < CDate(dtStart)) Then
Response.Write( "END TIME CANNOT PRECEDE START TIME!")
Else
Call InsertData(dtSt art, dtEnd)
Call LoadData()
End If
End Sub
Sub InsertData(ByVa l 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="pnlDataEntr y" runat="server">
............... .......
............... .......
</asp:Panel>
<asp:Panel ID="pnlShowData " runat="server">
<asp:DataGrid ID="dgETS"..... .........runat= "server">
<Columns>
<asp:BoundColum n............../>
<asp:BoundColum n............../>
<asp:BoundColum n............../>
<asp:BoundColum n............../>
<asp:EditComman dColumn CancelText="CAN CEL" EditText="EDIT"
HeaderText="EDI T" UpdateText="UPD ATE"/>
</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 EditCommandColu mn in the DataGrid
else the EditCommandColu mn 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?