whats wrong here, why is it complaining about closing the ")"
?
<asp:TemplateField HeaderText="Name" SortExpression="Name">
<ItemTemplate>
<%# FixNull((namespace.Student)(Container.DataItem), "Name"); %>
</ItemTemplate>
<EditItemTemplate>
<asp:dropdownlist id="ddlStudent" runat="server" datasourceid="CountyDataSource"
datatextfield="Name" datavaluefield="I开发者_如何学Pythond" autopostback="false">
</asp:dropdownlist>
</EditItemTemplate>
</asp:TemplateField>
protected string FixNull(object dataItem, string fieldName)
{
if (dataItem != null)
{
System.Data.DataRowView cls = (System.Data.DataRowView)dataItem;
if (!cls.Row.IsNull(fieldName))
return (cls[fieldName]).ToString();
else
return " ";
}
else
return " ";
}
Compiler Error Message: CS1026: ) expected
Source Error: Line: 133
Line 131: <asp:TemplateField HeaderText="Name" SortExpression="Name">
Line 132: <ItemTemplate>
Line 133: <%# FixNull((namespace.Student)(Container.DataItem), "Name"); %>
Line 134: </ItemTemplate>
Line 135: <EditItemTemplate>
<%# Eval("CountyName") == null ? " " : Eval("CountyName")%>
I think, you do not need the ;
it should just read:
<%# FixNull((namespace.Student)(Container.DataItem), "Name") %>
To simplify further you could use
<%# this.Eval("CountyName") ?? " "%>
Maybe try something like this:
<asp:TemplateField HeaderText="Name" SortExpression="Name">
<ItemTemplate>
<%# FixNull(DataBinder.Eval(Container.DataItem, "Name"))%>
</ItemTemplate>
<EditItemTemplate>
<asp:dropdownlist id="ddlStudent" runat="server" datasourceid="CountyDataSource"
datatextfield="Name" datavaluefield="Id" autopostback="false">
</asp:dropdownlist>
</EditItemTemplate>
</asp:TemplateField>
protected string FixNull(string dataItem)
{
if (!string.IsNullOrEmpty(dataItem))
{
return dataItem;
}
return " ";
}
精彩评论