Click here to Skip to main content
12,244,061 members (50,884 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C#
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....


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 30-Dec-12 20:44pm
Edited 30-Dec-12 21: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...
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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. Smile | :)
  Permalink  
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
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 4

try this..
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");
}
  Permalink  
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....
prashant patil 4987 31-Dec-12 5:10am
   
hey mrugesh.. this error occures when type caste is wrong. check your value assign part
Mrugesh08 31-Dec-12 5:11am
   
ok...i will chek it....
Mrugesh08 31-Dec-12 5:10am
   
plz sir see my code above...if u find any idea.....plz chek it....
prashant patil 4987 31-Dec-12 5:23am
   
i see your code..
i think you forget to execute query and to fill dataset.. check it..
Mrugesh08 31-Dec-12 5:56am
   
sir plz tell me.....plz sir.....
Mrugesh08 2-Jan-13 0:37am
   
hello sir..plz help me....i m still not getting the output
Mrugesh08 31-Dec-12 5:27am
   
sir can tell me where i write this query...and all code....
prashant patil 4987 2-Jan-13 1:01am
   
as you fill grid. in page load
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

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

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

Hope this will help for u..
  Permalink  
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....
Mrugesh08 31-Dec-12 5:23am
   
plz sir show me solution....plz tell me sir...my code is above....if u find any idea.....plz check my code....plz sir....

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160426.1 | Last Updated 31 Dec 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100