放置在runat=server表中的控件在更新时将SQL参数设置为NULL



我有一个页面,里面有FormView和一个纯html表。该表用于布局,并包含绑定到SqlDataSource的子控件数据。我的问题是,如果我将runat=server属性添加到表声明中,那么表中的所有控件都会在DataSource_Updateing事件中将我的SQL参数设置为NULL,从而使用NULL而不是实际值更新记录。如果我不添加runat=server,一切都很好。我的代码示例:

<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=server。但是,由于SQL记录是用NULL更新的,所以我对此没有任何进展。请告诉我代码中可能有什么错误。

尝试使用这个。

<!-- 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;
}

最新更新