Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

brain cramp 1

Status
Not open for further replies.

manny1234

IS-IT--Management
Mar 13, 2006
58
US
I should be able to figure this out but for some reason I cannot figure out where to start.

I have a datagrid that shows a list of available dates. You can click on these dates and they will pull up a report for that date. I have three other reports that I want to do the same thing for. But I do not want the datagrid to show up if the individual logged in doesn't have access to those reports. Here is the code I have. Don't laugh too hard, I know it is a mess.

Code:
<%@ Page Language="VB"  %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.SqlClient" %>
<script runat="server">
sub Page_Load(Sender As Object, E As EventArgs)

Dim ConnectionString As String = "server=NOPE ; database=DONOT ; User Id= NEED ; Password = THAT"

Dim CommandText2 As String = "SELECT * FROM [ResidualAvail] where status = 'global'"

Dim myConnection As New SqlConnection(ConnectionString)

Dim MyCommand2 As New SqlDataAdapter(CommandText2,myconnection)
	
Dim avail As DataSet
	
myConnection.Open

myCommand2 = New SqlDataAdapter(CommandText2,MyConnection)

avail = New DataSet()

myCommand2.Fill(avail,"[ResidualAvail]")

availGrid.DataSource = Avail.Tables("[ResidualAvail]")

availGrid.DataBind
			
myconnection.Close

End Sub	
</script>
<strong><font color="#330066">Residuals reports are available for: </strong>

	<p></p>	
	
<asp:datagrid 
id="AvailGrid"  showheader="false"
runat="server" CellSpacing="1"  CellPadding="3" BackColor="#efefef" ForeColor="Black" 
EnableViewState="False" autoGenerateColumns="false">

<columns>

<asp:HyperLinkColumn 
HeaderText="Month/Year" 
DataTextField="Month" 
DataTextFormatString="{0:MMMM, yyyy}"
DataNavigateUrlField="Month"
DataNavigateUrlFormatString="Residualstatement.aspx?id={0:'DatePart(YEAR,Month)='yyyy 'AND DatePart(MONTH,Month)='MM&'id2'=MMMM yyyy}"/>

</columns>
</asp:dataGrid>

The three other reports will have a datagrid identical to the one above accept the hyperlink will point to a different page. For these grids to show the following criteria needs to be met

session("Manager") needs to be "Yes"

Code:
SELECT AgentID FROM DivisionHistory WHERE ('" & Session("Number") & "' = AgentID)
Needs to return atleast one row.
 
You will have to figure out a way to authorize the user. Do you have something implemented?
 
i do, thats all taken care of i just need to have the criteria listed above met for them to view the datagrids

session("Manager") needs to equal Yes
and the query above needs to return atleast one row
 
I'm kind of confused as to what you are asking. You have a datagrid that has dates in it. And these dates are links that will show a report.

"But I do not want the datagrid to show up if the individual logged in doesn't have access to those reports."

So you want the whole datagrid to now show up if the user isn't in a session role? Just wrap it all in an If Statement.

Or are you saying that you don't want the row to show up? Or do you have more than one datagrid?
 
There will be a total of 4 datagrids. The very first one, the one I posted in the example is viewable to anyone. It is a generic report for our sales reps. The next 3 are for different levels of management. I do not want them to show up unless I specifically say Yes they have access and there is data in the particular tables. Access is controlled by session("Manager") and the SQL query I posted earlier will determine if there is data.
 
Just use jhurst's example using IFs.
ex:
If session("manager") = "some value" Then
Try
execute query
bind to datagrid
catch ex as exception
.. error handling
end Try
End If
 
Also, after they are determined to be in a management role, and after you fill the dataset (or better yet datatables) then do a datatable.rows.count and if it is greater than zero then you can set the datasource and databind.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top