如何修改事件的sql数据源参数?
这是我的场景:
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论