Sorry Nan but I think I explained my problem incorrectly.
Let me show the markup again with some slight changes:
<head><style type="text/css"> .dhide { display:none; }</style></head><div align="center"><asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" AllowPaging="true" OnPageIndexChanging="OnPageIndexChanging" PageSize="10"><Columns><asp:BoundField DataField="department"><ItemStyle CssClass="dhide"/><asp:HyperLinkField DataNavigateUrlFields="ManagerID,department" DataNavigateUrlFormatString="employeeDetails.aspx?ID={0}&Dept={1}" Text="Add Comments" /><asp:BoundField ItemStyle-Width="200px" DataField="empname" HeaderText="Employee Name" /><asp:BoundField ItemStyle-Width="250px" DataField="department" HeaderText="Department" /></Columns></asp:GridView></div>
On the markup above, I have department field hidden with css and these two lines:
<asp:BoundField DataField="department"><ItemStyle CssClass="dhide"/>
What I am trying to do is grab the value of the hiddenfield of dhide and pass it to code behind below:
Inherits System.Web.UI.Page Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load If Not Me.IsPostBack Then Me.BindGrid() End If End Sub Private Sub BindGrid() Dim constr As String = ConfigurationManager.ConnectionStrings("constr").ConnectionString Using con As New SqlConnection(constr) Using cmd As New SqlCommand("SELECT e.empID, e.empname, e.department, a.managerID, a.status FROM Emp e INNER JOIN Angulers a ON a.empID = e.empID WHERE a.status = 'Done' and e.ManagerID = '"&querystring("ID") & "' and e.department = '"&uerystring("dept") & "' ") 'We use parametized query to prevent sql injection attack ' Dim p1 As New SqlParameter("@dept", Session("dept")) 'cmd.Parameters.Add(p1) Using sda As New SqlDataAdapter() cmd.Connection = con sda.SelectCommand = cmd Using dt As New DataTable() sda.Fill(dt) GridView1.DataSource = dt GridView1.DataBind() End Using End Using End Using End Using End Sub
Something like:
SELECT e.empID, e.empname, e.department, a.managerID, a.status FROM Emp e INNER JOIN Angulers a ON a.empID = e.empID WHERE a.status = 'Done' and e.ManagerID = '"&querystring("ID") & "' and e.department = @dhide ")
This way, only records belonging to Manager's department are displayed.
How do I get this to work?
Thank you very much