Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
Hi ,
I want to design a page having 2 grid view which shows the detail of the employees which are going through cab on a day.
Now the requirement is that suppose we have 5 people going through the same cab in morning and evening.
Let the people be A,B,C,D,E.
when ever A logins and see the cab detail then he can see:
emp_id,emp_name,emp_address of every one on the grid but can not see other's phone number except his own.

Similarly when B logins and see the cab detail he can see every body's emp_id,emp_name,emp_address on the grid but can not see any one's phone number except his/her own.

Can any one help me in this........
Posted
Comments
[no name] 18-Apr-11 8:43am    
need some idea regarding database and just be specific regarding your question.

1 solution

Server side:

VB
Imports System.Data
Partial Class Default3
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim empds As DataSet
        Dim empTable As DataTable = New DataTable()
        Dim dr As DataRow

        empTable.Columns.Add(New DataColumn("Id"))
        empTable.Columns.Add(New DataColumn("Name"))
        empTable.Columns.Add(New DataColumn("Mobile"))

        dr = empTable.NewRow()
        dr("Id") = "A"
        dr("Name") = "A...."
        dr("Mobile") = "12345"
        empTable.Rows.Add(dr)

        dr = empTable.NewRow()
        dr("Id") = "B"
        dr("Name") = "B...."
        dr("Mobile") = "12345656"
        empTable.Rows.Add(dr)

        dr = empTable.NewRow()
        dr("Id") = "C"
        dr("Name") = "C...."
        dr("Mobile") = "123343445"
        empTable.Rows.Add(dr)

        GridView1.DataSource = empTable
        GridView1.DataBind()
    End Sub

    Protected Sub GridView1_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.PreRender
        For Each dr As GridViewRow In GridView1.Rows
            If dr.Cells(0).Text <> DropDownList1.SelectedItem.Text Then
                dr.Cells(2).Text = ""
            End If
        Next
    End Sub
End Class



Client Side

XML
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default3.aspx.vb" Inherits="Default3" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true">
            <asp:ListItem>A</asp:ListItem>
            <asp:ListItem>B</asp:ListItem>
            <asp:ListItem>C</asp:ListItem>
        </asp:DropDownList>
        <br />
        <asp:GridView ID="GridView1" runat="server" Width="731px">
        </asp:GridView>
    </div>
    </form>
</body>
</html>
 
Share this answer
 
Comments
preetpal kapoor 18-Apr-11 9:01am    
Hi sorry to say but you have not got my question .
I told that when a login then he can see his own phone number in the grid view .
i dont have to use any drop down there
mksharma38 19-Apr-11 9:21am    
Hi,
here drop down is only to show u, that how u can show phone No. for seleted user in grid.
u can provide login user id in place of "DropDownList1.SelectedItem.Text" or can use any check in place of
"If dr.Cells(0).Text <> DropDownList1.SelectedItem.Text Then"

if dr.Cells(0).Text contains user id then u can write as


Protected Sub GridView1_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.PreRender
For Each dr As GridViewRow In GridView1.Rows
If dr.Cells(0).Text <> loginUserId Then
dr.Cells(2).Text = ""
End If
Next
End Sub

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900