0

サーバータグ内でifステートメントまたはtrycatchブロックを使用できるかどうか疑問に思っていますか?すなわち:

'<%= if(grid!=null){((DropDownList)this.grid.FindControl("SRPType")).ClientID} %>'
4

3 に答える 3

1
<% try { %>

    <%= (grid != null) ?
            ((DropDownList)this.grid.FindControl("SRPType")).ClientID : ""
    %>
<% }
   catch {
    ... exception handling
   }
%>
于 2012-06-14T08:03:59.420 に答える
1

<%=%>構文を使用する代わりに、<%%>を使用し、Response.Writeを呼び出して出力値を書き込みます。例:

<%
    if(grid!=null)
    {
       try
       {
           var myList=(DropDownList)this.grid.FindControl("SRPType");
           if (myList!=null)
               Response.Write( myList.ClientID);
           else
               Response.Write("Where's my listbox?");
       }
       catch(Exception exc)
       {
          //Report error, maybe warn user
       }
    }

%>
于 2012-06-14T08:04:27.357 に答える
1

例外についてはわかりませんが、いつでもインラインifステートメントを使用できます...

<%=(grid != null ? ((DropDownList)this.grid.FindControl("SRPType")).ClientID : "" )%>
于 2012-06-14T08:05:59.080 に答える