gpt4 book ai didi

asp.net - 如何处理 Null(GridView Container.DataItem)

转载 作者:行者123 更新时间:2023-12-04 01:35:15 25 4
gpt4 key购买 nike

这里有什么问题,为什么它会提示关闭 ")"

<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="Id" 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 "&nbsp;";
}
else
return "&nbsp;";
}



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 ? "&nbsp;" : Eval("CountyName")%>   

关于asp.net - 如何处理 Null(GridView Container.DataItem),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4731063/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com