在SqlDataSource上应用FilterExpression并将结果绑定到GridView [英] Applying FilterExpression on SqlDataSource and binding the result to GridView

查看:110
本文介绍了在SqlDataSource上应用FilterExpression并将结果绑定到GridView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说明问题的样本表(EmployeeID,EmployeeName,ManagerID)

在我的gridView的项目模板中,有一个dropDownList,其绑定方式如下:

当您选择dataSource时,我将EmployeeName设置为正在显示的字段,并将EmployeeID设置为该值.然后在Edit绑定中,selectedValue是ManagerID.

我得到的每个EmployeeName的结果都可以看到ManagerName.

问题:

执行插入后,我尝试应用SqlDataSource.FilterExpression,但是引发错误,提示在列表中找不到dropDownList的值? FiterExpression位于EmployeeID上,该ID等于新插入的ID.

我创建了另一个sqlDataSource,它使用与选择源相同的选择命令,只是为了在插入后测试过滤​​器,实际上它给了我正确的结果.

我玩过sqlDataSource.databind()和gridView.databind(),但似乎无法弄清楚为什么它与源2一起工作而不在源1中工作?大概定位绑定?

谢谢

Sample table to explain the problem (EmployeeID,EmployeeName,ManagerID)

In my item template of my gridView I have a dropDownList which binds as follows:

When you choose dataSource I set EmployeeName to be the field that is being displayed and the EmployeeID for the value. Then in the Edit bindings the selectedValue is the ManagerID.

The result of this for every EmployeeName I get to see the ManagerName.

The question:

After I perform an insert I am trying to apply a SqlDataSource.FilterExpression however an error is thrown saying that the value of the dropDownList is not found in the list? The FiterExpression is on the EmployeeID which is equal to the newly inserted ID.

I created another sqlDataSource with the same select command as source one just to test out the filter after the insert and it actually gave me a correct result.

I played around with sqlDataSource.databind() and gridView.databind() but it seems I am not able to figure out why is it working with source 2 and not in source 1? probably positioning of binding?

Thank you

推荐答案

4277480写道:
4277480 wrote:

执行插入后,我正在尝试应用SqlDataSource.FilterExpression但是抛出错误,指出在列表中找不到dropDownList的值?

After I perform an insert I am trying to apply a SqlDataSource.FilterExpression however an error is thrown saying that the value of the dropDownList is not found in the list?



插入后是否更新了数据集?看起来过滤器正在处理旧数据,并且无法找到输入的新数据.尝试更新/重新获取数据以进行网格绑定并应用过滤器.



Did you updated the dataset after the insert? It looks like the filter is workin on the old data and not able to find the new data entered. Try updatting/re-fetching the data for grid bind and apply filter.


这篇关于在SqlDataSource上应用FilterExpression并将结果绑定到GridView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆