如何修改事件的sql数据源参数?

发布于 2024-12-06 04:07:25 字数 815 浏览 0 评论 0原文

这是我的场景:

Iv 将我的 sqlds 的参数链接到 dropDownList (dropDownList.selectedValue),但我希望这样当所选项目为“”时(在页面加载时添加没有文本的项目,以让用户选择一个空值,有点),我希望 sqlds 传递空值。这是我尝试过的,但它不起作用(给出错误说不存在这样的参数:(

protected void sqldsNewItem_Inserting(object sender, SqlDataSourceCommandEventArgs e)
{
    DropDownList ddl = dwNewItem.FindControl("ddlEffects") as DropDownList;
    if (ddl.SelectedItem.Text == "")
    {
        e.Command.Parameters["effect"].Value = null;
        e.Command.Parameters["numberOfTurns"].Value = null;
    }
}

我使用 FindControl 因为有问题的 dropDownList 位于模板中。)

这是我首先将其绑定到 sqld 的方式:

                    <asp:ControlParameter ControlID="dwNewItem$ddlEffects" Name="effect" PropertyName="SelectedValue"
                    DbType="int64" />

谢谢你们!

here is my scenario:

Iv linked a parameter of my sqlds to a dropDownList (dropDownList.selectedValue), but i want it so that when the selected item is "" (an item with no text is added on pageload, to let the user select a null value, sort of), i want the sqlds to pass null. Here is what i tried, but it doesnt work (gave the error saying no such parameter existed:

protected void sqldsNewItem_Inserting(object sender, SqlDataSourceCommandEventArgs e)
{
    DropDownList ddl = dwNewItem.FindControl("ddlEffects") as DropDownList;
    if (ddl.SelectedItem.Text == "")
    {
        e.Command.Parameters["effect"].Value = null;
        e.Command.Parameters["numberOfTurns"].Value = null;
    }
}

(I used FindControl because the dropDownList in question is in a template.)

And here is how i bound it to the sqlds in the first place:

                    <asp:ControlParameter ControlID="dwNewItem$ddlEffects" Name="effect" PropertyName="SelectedValue"
                    DbType="int64" />

Thanks guys!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文