简体   繁体   English

ASPxGridView无法使用ReadOnly False编辑行

[英]ASPxGridView Can't Edit Row With ReadOnly False

i'm currently working on an aspx website wherein I am using an ASPxGridView control. 我目前正在使用ASPxGridView控件的aspx网站上工作。 I am able to show up data on my GridView the way I want it to appear. 我可以按照自己希望的方式在GridView上显示数据。 However, my problem occurs when I click on the Edit button (provided by the control itself under a Command Column). 但是,当我单击“编辑”按钮(由“命令列”下的控件本身提供)时,会发生我的问题。 After clicking the said button, the GridView would change the row to an editable one. 单击上述按钮后,GridView会将行更改为可编辑的行。 However, I can't change the values inside the textboxes. 但是,我无法更改文本框内的值。 Please note that I have already set the ReadOnly Property to false both on the GridView's smart tag and on the xml source itself. 请注意,我已经在GridView的smart标签和xml源本身上都将ReadOnly属性设置为false。

I tried to create a test flag wherein the textbox's backcolor would change to blue whenever the ReadOnly property is set to true. 我试图创建一个测试标记,其中只要ReadOnly属性设置为true,文本框的背景色就会变为蓝色。 After running the program, the textbox would be colored in blue whether the ReadOnly is set to true or false. 运行该程序后,无论ReadOnly设置为true还是false,文本框都将显示为蓝色。

Are there any other properties that would help me make these textboxes editable? 还有其他属性可以帮助我使这些文本框可编辑吗? Thanks a lot! 非常感谢!

Cheers! 干杯!

I just ran into this same problem today. 我今天也遇到了同样的问题。 This symptom can appear if you're setting your datasource to an anonymous type: 如果将数据源设置为匿名类型,则会出现此症状:

void BindDataGrid()
{
    var gridData = from cm in MyCollection
                   select new 
                   {
                       UniqueId = cm.UniqueId,
                       Min = cm.SomeNumber ?? 0,
                       Max = cm.SomeOtherNumber ?? 0,
                       Description = cm.Description
                   };

    this.myGrid.DataSource = gridData;
    this.myGrid.DataBind();
}

The fix was to create a class for the grid to use. 解决方法是为网格创建一个类以供使用。 It was then able to figure out the data types for each cell, and they turned editable in the UI: 然后,它能够找出每个单元格的数据类型,并且它们在UI中变为可编辑的:

public class MyGridViewModel
{
    public Guid UniqueId { get; set; }
    public int Min { get; set; }
    public int Max { get; set; }
    public string Description { get; set; }
}

void BindDataGrid()
{
    var gridData = from cm in MyCollection
                   select new MyGridViewModel()
                   {
                       UniqueId = cm.UniqueId,
                       Min = cm.SomeNumber ?? 0,
                       Max = cm.SomeOtherNumber ?? 0,
                       Description = cm.Description
                   };

    this.myGrid.DataSource = gridData;
    this.myGrid.DataBind();
}

I made the mistake of trying to edit a protected property. 我犯了尝试编辑受保护属性的错误。 If a property has a public getter and a private or protected setter, then it will show up as a read only field in the edit form. 如果属性具有公共获取器和私有或受保护的设置器,则它将在编辑表单中显示为只读字段。 Hope this is of help to someone. 希望这对某人有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM