我建立了包含标签的简单习俗控制。 在习惯控制背后的代码中,我试图确定标签案文,但我没有提及错误。 任何想法?
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection connection = new SqlConnection(GetConnectionString());
connection.Open();
SqlCommand cmd = new SqlCommand("DisplayCustomerReviews", connection);
cmd.CommandType = CommandType.StoredProcedure;
XmlReader reader = cmd.ExecuteXmlReader();
//while (reader.Read())
while (!reader.EOF)
{
reader.ReadToFollowing("review");
reader.MoveToAttribute("Name");
string Name = reader.Value;
reader.MoveToAttribute("Message");
string Message = reader.Value;
reader.MoveToAttribute("Rating");
string Rating = reader.Value;
reader.MoveToAttribute("Date");
string Date = reader.Value;
reader.MoveToAttribute("Time");
string Time = reader.Value;
CreateReviewPanel(Name, Message, Rating, Date, Time);
}
reader.Close();
connection.Close();
}
private string GetConnectionString()
{
return ConfigurationManager.AppSettings["SQLConn"];
}
private void CreateReviewPanel(string Name,
string Message,
string Rating,
string Date,
string Time)
{
// need to check against nulls or empty strings to avoid
// extra reviewPanel being created at end of XML read.
if (Name != "")
{
Guid panelID = Guid.NewGuid();
Panel reviewPanel = new Panel();
reviewPanel.ID = panelID.ToString();
nameLabel.Text = Name;
messageLabel.Text = Message;
dateLabel.Text = Date;
timeLabel.Text = Time;
switch (Rating)
{
case "1":
ratingImage.ImageUrl = "~/images/one-star.gif";
break;
case "2":
ratingImage.ImageUrl = "~/images/two-stars.gif";
break;
case "3":
ratingImage.ImageUrl = "~/images/three-stars.gif";
break;
case "4":
ratingImage.ImageUrl = "~/images/four-stars.gif";
break;
case "5":
ratingImage.ImageUrl = "~/images/five-stars.gif";
break;
}
}
}
}
它说的是劳工。 案文 = 姓名为发生错误之处,随后是所有其他转让。