2014-02-20 45 views
2

我有一個需要由目錄填充的列表框。 我已經成功地填充了列表框的目錄,但我的問題是我無法獲得所選項目的值。我在SelectedIndexChanged事件上放置了一個斷點,但是我的web應用程序似乎沒有運行該代碼。當從列表中選擇一個項目時,Listbox selectedIndexChanged不會觸發

這裏是我的填充列表框代碼:

 lstDirectories.DataSource = dtDirectories; 
     lstDirectories.DataValueField = "DirectoryID"; 
     lstDirectories.DataTextField = "DirectoryName"; 
     lstDirectories.DataBind(); 

這是我如何從列表框中的SelectedIndexChanged事件中獲得價值:

 TextBox1.Text = lstDirectories.SelectedItem.Value.ToString(); 

我做錯了什麼嗎?謝謝您的幫助! :)

+4

你是否設置了屬性'Autopostback = true'? – mnieto

+1

nope。它被設置爲false @mnieto – danielle

+0

謝謝! @mnieto :)) – danielle

回答

8

使用屬性: -

AutoPostBack="True"

默認情況下它是False

+0

謝謝你! :) – danielle

相關問題