日期:2014-05-17  浏览次数:20427 次

girdview事件中给html控件属性赋值
前台
<asp:GridView ID="gvItemInfo">
 <Columns>
<asp:TemplateField   ItemStyle-HorizontalAlign="Center">
                <ItemTemplate>
                    <input id="txtQuantity" runat="server" type="text"  readonly="readonly"/>
                </ItemTemplate>
            </asp:TemplateField>
 <Columns>
</asp:GridView>

后台
protected void gvItemInfo_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
HtmlInputText txtQuantity = (HtmlInputText)(e.Row.Cells[0].FindControl("txtQuantity"));
txtQuantity.Attributes["ReadOnly"] = "false";
             
            }
        }

执行后txtQuantity的只读属性还是只读。
在后台事件中如何修改girdview中html控件的属性呢?
------最佳解决方案--------------------
txtQuantity.Attributes["readonly"]="readonly"
------其他解决方案--------------------
用了一个很二逼的方法解决了....
------其他解决方案--------------------
你这是设置readonly属性,我想要的是去掉readonly属性。
我用的是调用了一个js方法,但是我发现js只执行了一次。

txtQuantity.Attributes["ReadOnly"] = "false";

我要实现的就是将readonly属性设置为false.
引用:
txtQuantity.Attributes["readonly"]="readonly"

------其他解决方案--------------------
其实net_lover的回答并不正确,分还是给你了。