C# 如何在gridview中创建启用禁用文本框
如果它是一个ASP网页,你可以这样做C# 如何在gridview中创建启用禁用文本框,c#,webforms,C#,Webforms,如果它是一个ASP网页,你可以这样做 if (e.Row.DataItem != null) { System.Web.UI.WebControls.TextBox txtGLCode = e.Row.FindControl("txtGLCode") as System.Web.UI.WebControls.TextBox; string Enable = e.Row.Cells[4].Text; if (Enable == "True") {
if (e.Row.DataItem != null)
{
System.Web.UI.WebControls.TextBox txtGLCode =
e.Row.FindControl("txtGLCode") as System.Web.UI.WebControls.TextBox;
string Enable = e.Row.Cells[4].Text;
if (Enable == "True")
{
txtGLCode.Enabled = false;
txtGLCode.BackColor = Color.White;
}
}
其中column name是数据表中绑定到GridView的列。您可以使用代码隐藏中的id引用TextBox控件。要隐藏它,可以用两种方法,一种是从标记中隐藏,如下所示
<asp:gridview id="GridView" runat="server" onrowdatabound="GridView_RowDataBound" xmlns:asp="#unknown">
<columns>
<asp:templatefield headertext="TextBox">
<itemtemplate>
<asp:textbox id="TextBox1" runat="server" Text='<%#Bind("ColumnName")%>' />
</itemtemplate>
</asp:templatefield>
</columns>
表达式:当它为真时,将是您希望文本框显示的内容。我希望这能让您有所了解。这是windows应用程序还是asp网页?@Andile
System.web.UI.WebControls
-asp.net您的表中是否有一个单独的字段来表示true和false?您如何决定?无需担心,请与您共享标记代码和隐藏代码,以便我可以查看受保护的void xbrlgrid_RowDataBound(对象发送方,GridViewRowEventArgs e){if(e.Row.DataItem!=null){System.Web.UI.WebControls.TextBox txtGLCode=e.Row.FindControl(“txtGLCode”)as System.Web.UI.WebControls.TextBox;字符串Enable=e.Row.Cells[4]。文本;if(Enable==“True”){txtGLCode.Enabled=false;txtGLCode.BackColor=Color.White;}
<asp:gridview id="GridView" runat="server" onrowdatabound="GridView_RowDataBound" xmlns:asp="#unknown">
<columns>
<asp:templatefield headertext="TextBox">
<itemtemplate>
<asp:textbox id="TextBox1" runat="server" Text='<%#Bind("ColumnName")%>' Visible='<%# iif(Expression, true, false) %>'/>
</itemtemplate>
</asp:templatefield>
</columns>