简体   繁体   中英

How can I manipulate field properties dynamically?

I have some tables with the field property Active. The tables are using the same RadGridView. Par example the table MyLinqTable.

How can I dynamically update the contents of the field value Active?

private void CheckItemChanged()
{
   ...
       bool value = (GridView.CurrentRow.DataBoundItem as MyLinqTable).Active;
       (GridView.CurrentRow.DataBoundItem as MyLinqTable).Active = !value;
       Db.SubmitChanges();
   ...
}

This is my solution. You had to check if the DataBoundItem has a property with the name "Active". And then you can change the value of Active.

   private void CheckItemChanged()
   {
       if (
            GridView.CurrentRow != null && 
            GridView.CurrentRow.DataBoundItem != null &&
            GridView.CurrentRow.DataBoundItem.GetType().GetProperty("Active") != null)
       {
           dynamic dataItem = GridView.CurrentRow.DataBoundItem;
           bool value = dataItem.Active;
           dataItem.Active = !value;

           Db.SubmitChanges();

           RefreshItems();
       }
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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