I don't like to hard code strings into code if I can avoid it for internationlization reasons and for ease of editing at one place. So I put all my messages in a resource file. To display "Page # of #", I create a string resource named "PageNumberOfTotal" and its content is "Page {0} of {1}". Then I handle the DataBound event of the GridView control as follows:
protected void gdRecords_DataBound(object sender, EventArgs e)
{
//If there are records to display, then display the message
if (gdRecords.Rows.Count > 0)
{
lblNumberOfRecords.Visible = true;
lblNumberOfRecords.Text = string.Format(
MessageResource.Properties.Resources.PageNumberOfTotal,
gdRecords.PageIndex + 1,
gdRecords.PageCount);
} //If there isn't any records to display, the hide the label control
else lblNumberOfRecords.Visible = false;
}
No comments:
Post a Comment