禁用gridview中的按钮,该按钮是由另一个gridview中的select填充的

本文关键字:按钮 gridview 另一个 中的 select 填充 禁用 | 更新日期: 2023-09-27 18:13:49

场景如下:我有两个gridview。Gridview 1是这样的,例如

 __________________________________
| select | cell 2 | cell 3         |

当你点击单元格1中的select时,它会填充Gridview 2。

  _______________________________
 | cell 1 | cell 2 | BUTTON      |

然后当第二个gridview加载时,我试图禁用按钮,如果单元格2中的值为真。

我已经尝试使用rowdatabound事件禁用按钮。使用以下命令获取单元格文本信息。

在aspx页面

<asp:GridView ID="GridView10" runat="server" AutoGenerateColumns="False" 
                Font-Size="10px" CellPadding="2" 
                DataKeyNames="ID" DataSourceID="SqlDataSource35" Width="100%" 
                BorderColor="#CCCCCC" OnRowCommand="GridView10_RowCommand" 
                onrowdatabound="GridView10_RowDataBound"
后面代码中的

protected void GridView10_RowDataBound(object sender, GridViewRowEventArgs e)
{
    string cellt = e.Row.Cells[5].Text;
    if (cellt == "True")
    {
        Button btn = (Button)e.Row.Cells[6].Controls[1];
        btn.Enabled = false;
    }
}

通常这工作只是漂亮。但无论出于何种原因,在这种情况下,事件似乎并没有发生。有人对这个问题有什么见解吗?

禁用gridview中的按钮,该按钮是由另一个gridview中的select填充的

您确定您有正确的Gridview单元格吗?您可能使用了错误的单元格ID Where

protected void GridView10_RowDataBound(object sender, GridViewRowEventArgs e)
{
    string cellt = e.Row.Cells[CORRECT CELL?].Text;
     if (cellt == "True")
    {
        Button btn = (Button)e.Row.Cells[CORRECT CELL?].Controls[1];
        btn.Enabled = false;
    }
}

如果这是正确的单元格,你可以改变能见度属性

Buttonname。Visible = false

,你可以这样做

protected void GridView10_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        string cellt = e.Row.Cells[CORRECT CELL?].Tostring;
         if (cellt != "True") continue;
        {
            Button btn = (Button)e.Row.Cells[CORRECT CELL?].Controls[1];
            buttonname.visible = false;
            break;
        }
    }

请记住gridviews从单元格0开始

如果你把它作为单元格6,确保你从单元格0开始-所以单元格6可能是单元格5。

编辑,我注意到你问单元格是否有特定的文本,使用上面显示的。tostring