Write an Article Write a Tutorial Add a Fast Code* *Fast Code might be any helpful code with brief comment
Stem Cells Blood Banks Insurances .Net Hosting Credit Cards PC Rental Business
Tutorials: ASP .NET C# .NET VB .NET Articles: ASP .NET C# .NET VB .NET Fast Code: ASP .NET C# .NET VB .NET
BorderColor="Silver" HorizontalAlign="Center" RepeatDirection="Horizontal">
UserProfile.aspx is our Distanation Page where user will go to view the "Clicked user Profile". Where as "PicHandler.ashx" is our Picture Handler which server us to bring the picture from our DataBase. For more detailes how to save and retrive Pictures to DataBase see Saving and Retrieving Images From SQL Server Using ADO.NET 2.0 and to Display images in a gridview see Displaying an Image in a Gridview . Ok, now we have basic of how to display a picture in a "DataList". Now, will put four more controles on the Page.
Now, Our page is ready. what we are going to do next is to bind the above DataList with a DatTable. This DataTable is return by our Function like this;
public DataTable SearchedUsersDataTable(string keyTosearch) { DataTable dt = new DataTable("Users"); dt.Columns.Add("Name", typeof(string)); MembershipUserCollection memUserCol = Membership.GetAllUsers(); ProfileCommon prof; string searchKey = keyTosearch.ToLower(); foreach (MembershipUser Tuser in memUserCol) { prof = Profile.GetProfile(Tuser.UserName); if (Tuser.UserName.ToLower().Contains(searchKey)) { dt.Rows.Add(new Object[] { Tuser.UserName }); } else if (prof.FirstName.ToLower().Contains(searchKey)) { dt.Rows.Add(new Object[] { Tuser.UserName }); } else if (prof.LastName.ToLower().Contains(searchKey)) { dt.Rows.Add(new Object[] { Tuser.UserName }); } } return dt; }
protected void ButtonSearch_Click(object sender, EventArgs e) { UserDataList.DataSource = SearchedUsersDataTable(TextBoxSearch.Text); UserDataList.DataBind(); }
We are binding our DataList with pulled DataTable. Now, what about if some one is trying to search some"keywords" which return no "DataRow"? Just add the following code to the "Buttonsearched_Click" Event just after the DataList Binding. Now the code will look like this;
protected void ButtonSearch_Click(object sender, EventArgs e) { UserDataList.DataSource = SearchedUsersDataTable(TextBoxSearch.Text); UserDataList.DataBind(); if (UserDataList.Items.Count == 0) { LabelNoResult.Visible = true; LabelNoResult.Text = "No User Found for your search key!"; } else LabelNoResult.Visible = false; }
Hope it help.
28/02/2007 20:49:18 UTC
nice tut,
i used it but with one addition
i placed .ToLower after all KeyToSearch and in front of all .Contains entries, this fixes case sensative troubles
20/03/2007 09:48:23 UTC
Koen!
Nice idea. We are going to apply changing the tut.
20/03/2007 10:12:28 UTC
Nope, not there. It is weird.
Anyway i was wondering if u could elaborate further on the question(above) about how to display/list users who are online just like displaying new users, the link u provided above searches the users...
Im not sure exaclty where to put this code below and is KeyToSearch necessary as am not searchin? Sorry for the questions am new to asp.net. But appreciate your help and time.
if(usr.UserName.Contains(KeyToSearch) && usr.Isonline){
}
thnx
21/03/2007 19:53:17 UTC
What you want to do? Do you want to cerate a DataTable of the Users only?
22/03/2007 07:24:36 UTC
22/03/2007 10:31:20 UTC
This Article is exectly what you want
https://dotnet-friends.com/tutorials/asp/tutinaspb26b6f22-0ff0-48cf-8f96-0fd5d41bd620.aspx
If you dont want to sort the Table then return DataTable instead of DataView.
22/03/2007 16:07:30 UTC
Your Question have been moved to the Forum.
28/03/2007 06:26:40 UTC