如何使用后面的代码在Gridview的itemtemplate中的控件中添加readonly属性?

时间:2017-02-14 01:05:03

标签: c# asp.net gridview webforms

如何使用后面的代码在Gridview的itemtemplate中的控件中添加readonly属性? 我尝试过使用rowdatabound但总是得到null

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e){
if(e.Row.RowType == DataControlRowType.DataRow)
{
    Textbox mytxt = e.Row.FindControl("txtDate") as Textbox;
}
}

我尝试在asp.net页面添加readonly属性,但我无法获取文本框值(我使用javascript日历输入文本框)

1 个答案:

答案 0 :(得分:0)

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");
    }
}