Special Character does not displays in gridview

aditya mukherjee 1 Reputation point
2022-12-22T00:21:04.277+00:00

I have asp.net grid view which binds data from xml file but in the grid i am unable to see the special character which is present in the xml file. The actual value e.g. 4-­-0444 got modified to 4-­0444 due to html encoding. Is there any way to stop this encoding process globally in the website.

Asp.net Code

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" OnRowDataBound="GridView1_RowDataBound">
<Columns>
<asp:BoundField DataField="BillNo" HeaderText="BillNo" />
<asp:BoundField DataField="PageNo" HeaderText="PageNo" />
<asp:BoundField DataField="Activity" HeaderText="Activity" HtmlEncode="false" />
</Columns>
</asp:GridView>

C# Code

DataSet dsResult = new DataSet();
dsResult.ReadXml(new StreamReader(Server.MapPath("XMLFile1.xml")));
if (dsResult.Tables[0].Rows.Count > 0)
{
GridView1.DataSource = dsResult.Tables[0];
GridView1.DataBind();
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Cells[2].Text = Server.HtmlEncode(Convert.ToString(e.Row.Cells[2].Text));
}
}

XML

<Tenders>
<Ravina>
<BillNo>1</BillNo>
<PageNo>10</PageNo>
<Activity>Metals</Activity>
</Ravina>
<Ravina>
<BillNo>2</BillNo>
<PageNo>20</PageNo>
<Activity>Formworks</Activity>
</Ravina>
<Ravina>
<BillNo>3</BillNo>
<PageNo>30</PageNo>
<Activity>4-­-0444</Activity>
</Ravina>
</Tenders>

Final Output

BillNo PageNo Activity
1 10 Metals
2 20 Formworks
3 30 4-­0444 (This value got modified, actual value <Activity>4-­-0444</Activity> )

Thanks

ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,288 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,307 questions
{count} votes