I have the following GridView
, which has as DataSource
a List<T>
:
<asp:GridView ID="gvDownloads" UseAccessibleHeader="False"
AutoGenerateColumns="False" runat="server" PageSize="10" AllowPaging="true"
CellPadding="4" CellSpacing="1" GridLines="None" DataKeyNames="productid">
<EmptyDataTemplate>
No licenses found
</EmptyDataTemplate>
<Columns>
<asp:TemplateField HeaderText="Id" >
<ItemTemplate>
<%# Eval("ProductId")%>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Product Name">
<ItemTemplate>
<%# Eval("ProductName")%>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Stock Code">
<ItemTemplate>
<%# Eval("StockCode")%>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Which renders correctly and with the proper values.
Now, I would like to modify on the fly the field StockCode and in order to do so I have in my code behind:
Sub gvDownloads_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs) Handles gvDownlads.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
e.Row.Cells(2).Text = StockCodeConverter.Convert(e.Row.Cells(2).Text)
End If
End Sub
But the data cells corresponding to StockCode are empty. Now I tried to debug and for some reason the code finds just the value of the header row. The values of the other rows are string.Empty
or &nsbp. Might it depend on the List as DataSource?