Click here to Skip to main content
15,884,099 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello all...i want to show currently logged user data in the gridview...ie..when a user login..that user data show in the gridview ....not other user data....plz help me how can i do that....


C#
protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            string username;
            username = Session["cuname"].ToString();

            Label4.Text = username;
            txtdate.Text = System.DateTime.Now.ToShortDateString();
            string str;
            str = "select * from job_table where uname=" + Session["cuname"] + ""; ;
            btnupdate.Visible = false;
            if (!(Page.IsPostBack))
            {

                dv = new DataView();
                dv = objbal.viewrec();
                RadGrid1.DataSource = dv;
                RadGrid1.DataBind();

            }
        }
        catch
        {
            Response.Write("<script LANGUAGE='JavaScript' >alert('Please Login & Then Add  Details')</script>");
            //MessageBox.Show("Please Login & Then Add  Details");


        }

    }
    protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {

        ViewState["btnid"] = "del";
    }

    protected void ImageButton2_Click(object sender, ImageClickEventArgs e)
    {

        ViewState["btnid"] = "sel";
        RadGrid1.Visible = true;
    }

    void showgrid()
    {

        RadGrid1.DataSource = objbal.viewrec();
        RadGrid1.DataBind();
    }

    protected void RadButton1_Click(object sender, EventArgs e)
    {
        //Response.Write("<script LANGUAGE='JavaScript' >alert('Please Fill All The Details')</script>");
        string str;
        str = " : ";

        objdal.visit_id= Convert.ToInt32( txtid.Text);
        objdal.date=Convert.ToDateTime(System.DateTime.Now.ToShortDateString());
        objdal.radiologist = drpradio.Text;
        objdal.study_type = drpstudy.Text;
        objdal.account = drpaccount.Text;
        //RadMaskedTextBox1.Text=System.DateTime.Now.TimeOfDay.ToString();
        //objdal.time_duration=Convert.ToDateTime(RadMaskedTextBox1.Text);
        //RadMaskedTextBox1.Mask = "##:##";
        objdal.time_duration = Convert.ToDateTime(txtaudio.Text);
        objdal.uname = Label4.Text;

        objdal.remark = txtremarks.Text;
        //objdal.time_duration = txtremarks.Text;
        if (radiobtn.Items[0].Selected)
        {
            objdal.upload = radiobtn.Items[0].Text;

        }

        else if (radiobtn.Items[1].Selected)
        {
            objdal.upload = radiobtn.Items[1].Text;

        }
        else if (radiobtn.Items[2].Selected)
        {
            objdal.upload = radiobtn.Items[2].Text;
        }

        objbal.addrec(objdal);
        Label3.Text ="Congratulations!!Data Inserted Sucessfully";
        showgrid();


        txtdate.Text = "";
        txtid.Text = "";
        txtremarks.Text = " ";
        txtaudio.Text= "";
        drpradio.ClearSelection();
        drpstudy.ClearSelection();
        drpaccount.ClearSelection();


    }
Posted
Updated 30-Dec-12 20:12pm
v3
Comments
Mrugesh08 31-Dec-12 2:19am    
plz help me...how can i show currently logged user data in the gridview....my code is above...

When User Logged in
then On Login Button Click you have to maintain sessionto store user id
i.e. Session["UserId"] = "User Id Value";

then you fire query "select * from user_Table where userid = "+ Session["UserId"] +"";
After getting Dataset you have to set Values to lables controls..


Happy Coding. :)
 
Share this answer
 
Comments
Mrugesh08 31-Dec-12 2:08am    
my code is below....
Mrugesh08 31-Dec-12 3:40am    
plz see above my code..and plz help me how can i display data of logged user......
prashant patil 4987 31-Dec-12 3:56am    
hey check my solution 4
try this..
C#
Str = "Your Select Query to get user details as per Session("UserId")";
CMD = new SqlCommand(Str, CON);
ADP = new SqlDataAdapter(CMD);
sADP.Fill(DS, "LOGIN");
if (DS.Tables("LOGIN").Rows.Count == 0) {

    Session["UserID"] = UserID.Text.Trim.ToUpper;
    Session["UserName"] = DS.Tables("LOGIN").Rows(0)("Name").ToString.Trim;
   ......

    Response.Redirect("Your Main Page after login");
}
 
Share this answer
 
Comments
Mrugesh08 31-Dec-12 4:06am    
yes but my primary key is username...so can you plz tell me the code for that...and what is my select query so i can display currently logged user data in the gridview..i m using 3 tier architecture......
prashant patil 4987 31-Dec-12 4:23am    
hey your query is like below:
Session["UserId"] = store user name.
"Select * from Your_User_Table where username = "+Session["username"]+"";
Mrugesh08 31-Dec-12 5:01am    
not working sir..plz tell me another way...
prashant patil 4987 31-Dec-12 5:04am    
hey Mrugesh which error occred now..post it in comment
Mrugesh08 31-Dec-12 5:07am    
object reference not set instance of an object....
Whenever user is Redirecting from Login.aspx page to Home.apsx page add UserID or UserName with QueryString and access that Query string in Home.aspx

C#
btnLogin_Click(object sender, EventArgs e)
{
    if(Is User valid)
    {
        Response.Redirect("Home.aspx?UserID="+txtUserID.Text+"");
    }
}


Hope this will help for u..
 
Share this answer
 
Comments
Mrugesh08 31-Dec-12 3:38am    
no.....i have a one form with add,update button..and i have a one gridview..user add the record,update the record..but in gridview all the records are displyed..i want to show only that user who is login ..not any more...plz help me...
V_R 31-Dec-12 4:58am    
whatever it is, once user loggedIn means you will be having UserID based on that you can project your data.
Mrugesh08 31-Dec-12 5:56am    
no username is pk..and i want that particular user data in the gridview....no more data..only that data is displayed in the gridview....plz see above my code....
Mrugesh08 31-Dec-12 5:57am    
plz sir show me solution....plz tell me sir...my code is above....if u find any idea.....plz check my code....plz sir....
Mrugesh08 31-Dec-12 5:04am    
no username is pk..and i want that particular user data in the gridview....no more data..only that data is displayed in the gridview....plz see above my code....

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