这是 IMGUserlabel 在 .Apsx 中的位置:
这是 Aspx.Cs :
public void GetUserDetails(int id)
{
string getUserDetail = "Select ID,Email,Name,Country,Convert(varchar (20), RegisterDate, 106) RegisterDate,Convert(varchar (20), LastLogin, 106) LastLogin ,Description,ImageName FROM [User] where Id='" + id + "'";
dt = dbClass.ConnectDataBaseReturnDT(getUserDetail);
if (dt.Rows.Count > 0)
{
IMGUserLabel.Text = dt.Rows[0]["Name"].ToString();
NameLabel.Text = dt.Rows[0]["Name"].ToString();
UserImage.ImageUrl = "~/UserImage/" + dt.Rows[0]["ImageName"].ToString();
lblCreated.Text = dt.Rows[0]["RegisterDate"].ToString();
LabelLastLogin.Text = dt.Rows[0]["LastLogin"].ToString();
lblCreated.Text = dt.Rows[0]["RegisterDate"].ToString();
LabelAboutMe.Text = dt.Rows[0]["Description"].ToString();
}
}
并显示错误:名称“'IMGUserLabel' 在当前上下文中不存在”但是其他标签正确显示数据
好的,我已经添加了这个,并且没有错误:) 但是标签上没有显示任何数据,它只是说“标签”:
void Item_Bound(Object sender, DataListItemEventArgs e)
{
string getUserDetail = "Select ID,Email,Name,Country,Convert(varchar (20), RegisterDate, 106) RegisterDate,Convert(varchar (20), LastLogin, 106) LastLogin ,Description,ImageName FROM [User] where Id='" + e + "'";
{
// Retrieve the Label control in the current DataListItem.
Label IMGUserLabel = (Label)e.Item.FindControl("IMGUserLabel");
IMGUserLabel.Text = dt.Rows[0]["Name"].ToString();
}
}
这是 Result ,标签应该显示该图像的用户