Gridview循环每一行在fropdownlist的数据源中给出不同的数据

发布于 2024-12-03 12:55:37 字数 496 浏览 0 评论 0原文

我有一个带有一列下拉列表的网格视图。在此下拉列表中,不同行将显示不同的数据。因为通过这个下拉列表,我们可以为这个员工(当前行)选择一个经理,所以它不应该限制这个员工的名字。

我的问题是所有下拉列表仅显示没有最后一行员工而不是当前行员工的列表。

我的代码隐藏是这样的:

For Each row As GridViewRow In GVListeSalarie.Rows
            Dim s_id As TextBox = CType(row.FindControl("SalarieID"), TextBox)
            Dim strSql As String = "select * from p_salarie where sal_id <>" & s_id.Text
            dsmanager.SelectCommand = strSql
Next

有谁知道为什么它只显示最后一次循环的结果?提前致谢。

I have a gridview with one column of dropdownlist. In this dropdownlist, different row will show different data. because through this dropdownlist, we can choose a manager for this employee (the current row), so it shouldn't contrain the name of this employee.

My problem is all the dropdownlists are showing the list only without the last row's employee instead of the current row employee.

My codebehind is like this:

For Each row As GridViewRow In GVListeSalarie.Rows
            Dim s_id As TextBox = CType(row.FindControl("SalarieID"), TextBox)
            Dim strSql As String = "select * from p_salarie where sal_id <>" & s_id.Text
            dsmanager.SelectCommand = strSql
Next

Does anyone know why it shows only the result of the last time loop? Thanks in advance.

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

薆情海 2024-12-10 12:55:37

我找到了答案,我将 sqldatasource 移动到 gridview 中,这样我就可以使每一行中的下拉列表都有自己的数据源。
隐藏代码是这样的:

For Each row As GridViewRow In GVListeSalarie.Rows
            Dim s_id As TextBox = CType(row.FindControl("SalarieID"), TextBox)
            Dim strSql As String = "select * from p_salarie where sal_id <>" & s_id.Text
            Dim dsrow As SqlDataSource = CType(row.FindControl("dsmanager"), SqlDataSource)
            dsrow.SelectCommand = strSql

        Next

I found the answer, I moved my sqldatasource into the gridview, thus I can make the dropdownlist in each line has its own datasource.
And the codebehind is like this:

For Each row As GridViewRow In GVListeSalarie.Rows
            Dim s_id As TextBox = CType(row.FindControl("SalarieID"), TextBox)
            Dim strSql As String = "select * from p_salarie where sal_id <>" & s_id.Text
            Dim dsrow As SqlDataSource = CType(row.FindControl("dsmanager"), SqlDataSource)
            dsrow.SelectCommand = strSql

        Next
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文