0
votes

i'm currently working on an aspx website wherein I am using an ASPxGridView control. I am able to show up data on my GridView the way I want it to appear. 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. 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.

I tried to create a test flag wherein the textbox's backcolor would change to blue whenever the ReadOnly property is set to true. After running the program, the textbox would be colored in blue whether the ReadOnly is set to true or false.

Are there any other properties that would help me make these textboxes editable? Thanks a lot!

Cheers!

2
When you say "However, I can't change the values inside the textboxes" you mean, that you can't type in cell? - Metaller
Yes. I can't type in the cell. For instance, when the original value inside the cell is "1000", upon clicking the edit button it will show me the textbox version with the same value inside "1000". I can't edit it. I can't type nor change it. Thanks for responding. - Smiley
Have you set KeyFieldName grid's property? Also check that you handle events like RowUpdating or there is UpdateCommand if you use a data source control. - kolbasov
Yes I have a KeyFieldName property set. I also am able to handle RowUpdating which can be tested through breakpoints. My only problem is that I can't edit what's inside the textbox even through all my ReadOnly Property is already set to false. - Smiley
Is your grid bound to an Entity or a Dataset? if the field corresponds to a Readonly field in the datasource, it may become readonly. Anyway, can you try setting "e.Editor.Readonly = False" for that column in "CellEditorInitialize" event, and see if that works? - Akhil

2 Answers

6
votes

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:

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();
}
0
votes

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.