如何在gridview中显示当前记录的用户数据 [英] how to show currently logged user data in the gridview
本文介绍了如何在gridview中显示当前记录的用户数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好...我想在gridview中显示当前记录的用户数据...即..当用户登录时...用户数据显示在gridview ....而不是其他用户数据.... PLZ帮帮我怎么做....
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();
}
推荐答案
当用户登录
然后在登录按钮上单击您必须维护会话以存储用户ID
即会话[UserId] =用户ID值;
然后你开始查询select * from user_Table where userid =+ Session [UserId] +;
获得数据集后你必须将值设置为标签控件..
快乐编码。 :)
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. :)
试试这个..
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");
}
每当用户从Login.aspx页面重定向到Home.apsx页面时,使用QueryString添加UserID或UserName并访问Home.aspx中的查询字符串
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..
这篇关于如何在gridview中显示当前记录的用户数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文