2014年7月13日 星期日

[RESOLVED] Membership.GetAllUsers() databound to other table.


Hi All,


I have a question which I could not succeed.: I have a table in SQL server in  which Usernames are primary key and I want to get some data from this table with returns only online users in a gridview. I am using standard asp.net Membership privider. I could
get all the list of online users with the code below.: 


Dim users As MembershipUserCollection
' Bind users to ListBox.
Dim onlineUsers As New List(Of MembershipUser)()
For Each user As MembershipUser In Membership.GetAllUsers()
If user.IsOnline Then

onlineUsers.Add(user)

End If
Next

            DataKeyNames="UserName" EnableModelValidation="True">

SortExpression="UserName" />



SortExpression="cinselTercih" />



I need urgent help.. 


Could you please help me how to do it?



hello ozersenol,


i think you want extra data fields from your user table? like il,yas,ulke etc and these fields are not the part of membership user. if this is what you want, then you may have to write your own User class with these fields and a method of get the user-details
for the given username. So, your code may be like this,


Dim users As MembershipUserCollection
' Bind users to ListBox.
Dim onlineUsers As New List(Of MembershipUser)()
Dim customUsers As New List(Of CustomUser)()
For Each user As MembershipUser In Membership.GetAllUsers()
If user.IsOnline Then

onlineUsers.Add(user)

customUsers.Add ( GetUserDetailsByUsername(user.Username) )

End If
Next

gridview1.datasource = customUsers;
gridview1.databind();



or you can have a look at similar thread post.


http://forums.asp.net/t/1131790.aspx/1


沒有留言:

張貼留言