Search code examples
c#asp.netgridviewsqldatasource

When Update a field with ReadOnly Mode in GridView ,value of that is empty


One of the few fields that have their ReadOnly property equal to True then Edit and Update the value field is empty ReadOnly property is recorded. I also have a ReadOnly property and its value is not empty. (GridView to the SqlDataSource is connected) How to solve this problem?


Solution

  • If you do not wish to update this value, remove it from your UpdateCommand on your asp:SqlDataSource.

    If you wish to get this value on your update command you need to included it on

    <asp:SqlDataSource ...
    <UpdateParameters>
      <asp:Parameter Name="YourFieldName" Type="Bool" />
      ...
    </UpdateParameters>
    

    The ReadOnly field is just say that when you go to edit mode, for this field is not change to control for give the opportunity to change, but the values on SqlDataSource is not affected by this readonly flag.