带有来自文本框的绑定参数 DateTime 的 Gridview 在排序时抛出 DateTimeException
我在使用 ASP.NET GridView 时遇到问题。
GridView 设置为通过 SqlDataSource 从存储过程中检索行。 Gridview 有一个 BoundField,它从表单上的 ASP.NET 文本框中填充存储过程的 DateTime 参数。
当我在 ASP.NET 文本框中输入无效的日期时间,然后单击 GridView 的任意列对其进行排序时,GridView 在其 PreRender 事件中抛出 FormatException:“位置 0 处的字符无效”
如何拦截或阻止用户当 TextBox 中包含无效的 DateTime 时对 GridView 进行排序?
我已经尝试过表单验证器,但看起来这些验证器没有考虑 GridView 点击。我的一个想法是手动执行数据绑定和排序,以便我可以阻止正在进行的错误排序。有什么想法吗?
I'm having issues with an ASP.NET GridView.
The GridView is set up to retrieve rows from a stored procedure via a SqlDataSource. The Gridview has a BoundField which fills in a DateTime parameter for the stored procedure from an ASP.NET Textbox on the form.
When I enter an invalid DateTime into the ASP.NET Textbox and then click any column of the GridView to sort it, the GridView throws a FormatException in its PreRender event: "invalid character at position 0"
How can I intercept or stop a user from sorting the GridView while the TextBox has an invalid DateTime in it?
I've already tried form validators but it looks like those don't take GridView clicks into account. One thought I had was to perform the data binding and sorting manually so that I can stop a bad sort in progress. Any thoughts?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我通过扩展 Textbox.OnTextChanged 事件解决了这个问题,如下所示:
这在 GridView 排序之前触发!问题解决了。
I solved this by extending the Textbox.OnTextChanged event like so:
This fires before the GridView sorts! Problem solved.