更新/插入实体上下文后如何刷新下拉列表 [英] How do I refresh dropdownlist after updating/inserting entity context

查看:66
本文介绍了更新/插入实体上下文后如何刷新下拉列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个下拉列表,在我对实体进行更新和插入后,我想刷新以显示新插入的联系人姓名。这是我插入新记录的代码:

I've a dropdownlist that after I make updates and inserts to the entity I would like to refresh to display the newly inserted contact name. Here's my code for inserting the new record:

private void btnCreate_Click(object sender, EventArgs e)
        {
            var nextContact = context.Contacts.OrderBy("it.ContactID DESC").First();
            int nextContactID = nextContact.ContactID + 1;
            string[] name = txtTenant.Text.Split(' ');
            var contact = Contact.CreateContact(nextContactID, name[0].ToString(), name[1].ToString());
            var address = new Address();
            address.Address1 = txtAddress.Text;
            contact.ContactNumber = txtContactNum.Text;
            address.Mortgage = txtMortgage.Text;
            address.RemainingMortgage = txtRemainingMortgage.Text;
            address.Rent = txtRent.Text;
            address.Period = cboPeriod.SelectedIndex;
            address.RentArrears = txtRentArrears.Text;
            address.Rates = txtRates.Text;
            address.RatesUpToDate = chkRates.Checked;
            address.RentArrears = txtRentArrears.Text;
            address.Repairs = txtRepairs.Text;
            //join the new address to the contact
            address.Contact = contact;
            //add new graph to the contact
            context.AddToContacts(contact);
            context.SaveChanges();
        }

推荐答案

插入后调用函数QueryContacts()
After the insertion call the function QueryContacts()


这篇关于更新/插入实体上下文后如何刷新下拉列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆