0
在我的用戶控件中,我有一個文本框,用於創建新的成員資格用戶。每個列表框都有一個設置爲membership.getallusers()
的數據源來填充列表框。當列表框索引被改變時,它填充文本框以允許編輯。我想完成的是:讓每個用戶列表框都刷新以顯示創建的新用戶。即使我在成功創建用戶後調用databind()
,它也不會更新。在表單上,我檢查是否listbox.items.count < 1
,然後撥打電話databind()
,確實能正常工作。有任何想法嗎?ASP.NET VB列表框DataBind不工作
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
If ListBox3.Items.Count < 1 Then
For Each item As MembershipUser In Membership.GetAllUsers(0, Membership.GetAllUsers.Count + 1, Membership.GetAllUsers.Count)
ListBox3.Items.Add(item.UserName)
Next
Label1.Text = ListBox3.Items.Count
username = ListBox3.Items(0).ToString
Else
ListBox1.DataBind()
ListBox3.DataBind()
End If
user = Membership.GetUser
ListBox1.DataSource = Membership.GetAllUsers
ListBox1.DataBind()
ListBox2.DataSource = Roles.GetAllRoles
ListBox2.DataBind()
' ListBox3.DataSource = Membership.GetAllUsers
'ListBox3.DataBind()
End Sub
Protected Sub ListBox3_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListBox3.SelectedIndexChanged
txtUsername.Text = user.UserName
txtEmail.Text = user.Email
txtQuestion.Text = user.PasswordQuestion
End Sub
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Try'Creates a new user
Dim status As System.Web.Security.MembershipCreateStatus
Membership.CreateUser(txtUsername.Text, txtPassword.Text, txtEmail.Text, txtQuestion.Text, txtAnswer.Text, True, status)
Label1.Text = "User " & txtUsername.Text & " was created"
'ListBox3.Items.Clear()
ListBox1.DataBind()
'ListBox3.DataBind()
Catch ex As Exception
Label1.Text = "Error:" & ex.Message
End Try
End Sub
真棒工作。我沒有意識到數據源實際上是在抓取數據。所以我認爲數據綁定只是從內存數據源加載? – Bob 2013-04-22 22:02:27
正確:首先得到數據,數據綁定創建內部控制結構 – Kenneth 2013-04-22 22:03:11
酷。非常感謝! – Bob 2013-04-22 22:57:49