Replace characters in string with values

后端 未结 3 623
孤城傲影
孤城傲影 2020-12-22 11:56

I have a string which is a paragraph written on the aspx side. It goes like this:

The new student, {student_name} has the following grades -
Mat

3条回答
  •  死守一世寂寞
    2020-12-22 12:02

    You certainly can use String.Replace, but typically ASP.NET apps are written using labels as placeholders and then modifying the values in the code-behind.

    So your MyFile.aspx would contain The new student, [lblStudentName] has the following grades - Maths - [lblMathGrade] Science - [lblScienceGrade] ... and so on

    Then in your MyFile.aspx.cs (or MyFile.aspx.vb)

    this.lblStudentName.Text = "John Doe";
    this.lblMathGrade.Text = "A-";
    this.lblScienceGrade.Text = "F";
    

    There are also many other better techniques you could use, such as a repeater control, then binding the sql results to this control.

提交回复
热议问题