简体   繁体   English

如何通过使用后面的代码在Gridview的itemtemplate内的控件上添加只读属性?

[英]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.

相关问题 在asp.net中,要启用/禁用图像按钮,如何在asp.net代码后面的文件中访问Gridview-> Itemtemplate->面板的ImageButton控件 - In asp.net, To enable/disable imagebutton, How can I access ImageButton control of Gridview->Itemtemplate->panel in asp.net code behind file 从背后的代码在Web用户控件上的Listview ItemTemplate中填充Gridview - Populating Gridview inside Listview ItemTemplate On Web User Control from Code Behind 如何从 xaml 中的 ItemTemplate 访问在代码中定义的用户控件的依赖项属性? - How can I access a dependency property of a user control that was defined in code behind from a ItemTemplate in xaml? 如何访问放置在GridView的ItemTemplate内的图像控件的ImageUrl属性 - How to access ImageUrl property of the Image Control placed inside a ItemTemplate in the GridView 如何知道 GridView 的 ItemTemplate 中服务器控件的 ID? - how to know the id of server control inside the ItemTemplate of a GridView? 如何从用户控件页面后面的代码在ListView的ItemTemplate中找到控件? - how to find control in ItemTemplate of the ListView from code behind of the usercontrol page? 我想在后面的代码中的UL标签内添加图表控件 - I want to add a chart control inside a UL tag in code behind 如何在C#后面的代码中获得标签在ItemTemplate中的位置? - how can I get the label where in the ItemTemplate with code behind C#? 如何通过页面内部加载背后的代码在gridview中隐藏超链接控件? - How to hide a hyperlink control inside gridview through code behind inside page load? 您可以在后面的代码中向GridView添加属性吗? - Can you add attributes to a GridView in code behind?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM