Your suggestion was most helpfull. I get Book.Title with blank BookType.Name! I thought the blank name was null but it seems that it is not. I would like "N/A" value instead of this empty field. I've accomplished this in another example using
<%# (Eval("FieldName") == null) ? "N/A" : Eval("FieldName") %>
for the current example with field BookType.Name it should be something like this
<%# (Eval("Name") == null) ? "N/A" : Eval("Name") %>
but it doesn't work for these empty strings, which should be null, but they are not.
I've tried this
<%# (Eval("Name").Equals("Poetry")) ? "N/A" : Eval("Name") %>
and it works fine, for Poetry there is now "N/A", and for everything else it shows the real name as it should.
The question is how to set value "N/A" instead of these empty fields I get in gridview.
This is HTML code:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:TemplateField HeaderText="Title" ItemStyle-Width="350">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("Title")%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Name" ItemStyle-Width="150">
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# (Eval("Name") == null) ? "N/A" : Eval("Name") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Code behind:
ResultsetFields fields = new ResultsetFields(2);
fields.DefineField(BookFields.Title, 0);
fields.DefineField(BookTypeFields.Name, 1);
RelationPredicateBucket bookFilter = new RelationPredicateBucket();
bookFilter.Relations.Add(BookEntity.Relations.BookTypeEntityUsingBookTypeId, JoinHint.Left);
DataTable results = new DataTable();
DataAccessAdapter adapter = new DataAccessAdapter();
adapter.FetchTypedList(fields, results,
bookFilter, 0,
new SortExpression(BookTypeFields.Name | SortOperator.Ascending), true);
GridView1.DataSource = results;
GridView1.DataBind();
Hopefully you can help me once again. Thanks!!
Edit:
I managed to do this with:
(Convert.ToString((Eval("Name"))).Equals("")) ? "N/A" : Eval("Name")
but it doesn't seem like a good idea, i'll leave it like this if noone has a better idea...
Thx!!