Using the common form of DataBinder.Eval
doesn’t really work for field names that contain .
.
The alternative forms are:
((System.Data.DataRowView)Container.DataItem)["C.json"]
or
DataBinder.GetPropertyValue(Container.DataItem, "C.json")
I personally find the second most elegant and simple.
That’s because DataBinder.Eval
wait, in the second parameter, a expression
to find the column name or property of a class. Thus, the point influences the resolution of the parameter.
See more details about the method DataBinder.Eval
in the MSDN.
An example
THE HTML:
<asp:Repeater ID="ProductList" runat="server">
<ItemTemplate>
O id é: <%# DataBinder.Eval(Container.DataItem, "id") %> <br />
Para o item: <%# DataBinder.Eval(Container.DataItem, "item") %> <br />
Valor com ponto: <%# ((System.Data.DataRowView)Container.DataItem)["C.json"] %> <br />
Outra forma: <%# DataBinder.GetPropertyValue(Container.DataItem, "C.json") %> <br />
<br />
<hr />
</ItemTemplate>
</asp:Repeater>
C# no page_load
to fill the:
protected void Page_Load(object sender, EventArgs e)
{
var products = new DataTable();
DataRow row;
products.Columns.Add(new DataColumn() { ColumnName = "id" });
products.Columns.Add(new DataColumn() { ColumnName = "item" });
products.Columns.Add(new DataColumn() { ColumnName = "C.json"});
for (int i = 0; i < 10; i++)
{
row = products.NewRow();
row["id"] = i;
row["item"] = "item " + i.ToString();
row["C.json"] = "valor com . no nome";
products.Rows.Add(row);
}
ProductList.DataSource = products;
ProductList.DataBind();
}
The result:
You could put the exception you’re getting?
– anmaia