开发者

list box control in asp.net

Hello friends I have a list box control in my asp.net project. I want to know how to get selected index to set currently updated item in database. Please help me with this. Do i need to perform some data base operation to find the key f开发者_Python百科or currently updated data and then i'll have to set it or there exist some property to deal with this? thanks in adavance


One thing to watch out for, which I have come accross more than once is that if you call your CompanyListBox() method in your Page_Load method, you will lose the selected index unless it is only called on the first page load. To make sure of this, place your call to CompanyListBox() within the following block:

        if(!Page.IsPostBack)
        {
            CompanyListBox();
        }

You can access the selected index in your postback by using the following code:

var id =  (Int32)listCompany.SelectedItem.Value

Then it is up to you to use that in your data access to update the record in the database. Looks to me that you are using some kind of framework or manager class for your database access. The companyManager should have methods for saving your updated item to the database. Good luck.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜