[英]How can I add readonly attribute at a control inside itemtemplate of Gridview by using code behind?
How can I add readonly attribute at a control inside itemtemplate of Gridview by using code behind? 如何通过使用后面的代码在Gridview的itemtemplate内的控件上添加只读属性? I have tried using rowdatabound but always get null
我尝试使用rowdatabound但始终为null
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e){
if(e.Row.RowType == DataControlRowType.DataRow)
{
Textbox mytxt = e.Row.FindControl("txtDate") as Textbox;
}
}
I tried add readonly attribute in asp.net page but i cant get the textbox value(i use javascript calendar to input the textbox) 我尝试在asp.net页面中添加readonly属性,但无法获取文本框值(我使用JavaScript日历输入了文本框)
try 尝试
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e){
if(e.Row.RowType == DataControlRowType.DataRow)
{
TextBox mytxt = e.Row.FindControl("txtDate") as TextBox;
mytxt.Attributes.Add("readonly", "readonly");
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.