2013-11-22 18 views
0

我有一個FormView和一個普通的html表格。該表用於佈局,幷包含子控件data-bind到SqlDataSource。我的問題是,如果我將runat = server屬性添加到表聲明中,則表中的所有控件都將DataSource_Updating事件中的SQL參數設置爲NULL,因此記錄將使用NULL而不是實際值進行更新。如果我不添加runat = server,一切正常。我的代碼示例:放置在runat = server表中的控件在更新時將NULL參數設置爲NULL

<asp:FormView ID="SettingsFormView" runat="server" DataKeyNames="Id" DataSourceID="SettingsDataSource" 
     DefaultMode="Edit" Width="560px"> 
     <EditItemTemplate> 
      <strong>Settings</strong> 
      <table runat="server" width="350px"> 
       <tr> 
        <td width="160"> 
         Time (sec) 
         <dx:ASPxSpinEdit ID="textTime" runat="server" 
          Height="21px" Number="0" Value='<%# Bind("Time") %>' Width="104px" /> 
         <br /> 
        </td> 
        <td> 
         &nbsp; 
        </td> 
       </tr> 
      </table> 
     </EditItemTemplate> 
</asp:FormView> 

我希望能夠刪除(設置爲不可見)的某些行背後的代碼,這就是爲什麼我需要設置RUNAT =服務器。然而,我無法得到任何地方,因爲SQL記錄更新爲NULL。請告知,我的代碼中可能有什麼問題。

回答

0

試着用這個。

<!-- toggle through OnLoad (can use ID as well) --> 
<asp:PlaceHolder runat="server" OnLoad="MakeVisibleOrNot"> 
<tr> 
    ... 
</tr> 
</asp:PlaceHolder> 

,並在後面的代碼:

protected void MakeVisibleOrNot(object sender, EventArgs e) 
{ 
    ((Control) sender).Visible = ConfigUtil.DisplaySummaryComment; 
} 
相關問題