[英]Disabling a button in a gridview that's populated from a select in another gridview
这是场景。 我有2个gridviews。 Gridview 1例如这样
__________________________________
| select | cell 2 | cell 3 |
然后,当您单击单元格1中的选择时,它将填充Gridview 2。
_______________________________
| cell 1 | cell 2 | BUTTON |
然后,当第二个gridview加载时,如果单元格2中的值为true,则尝试禁用该按钮。
我试图使用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单元格吗? 您可能使用了错误的单元格ID
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。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.