ASP.net displaying data from SQL data source
I'm using LINQ to SQL to grab information from my SQL database. I have a GridView which shows all the top level information - in this case a list of groups (i.e. admin, users and so on). When a user clicks say the admin group, I want to be able to show each member in that group. I have the following code which grabs the information from the da开发者_Python百科tabase:
DataClassesDataContext dc = new DataClassesDataContext();
GridViewRow row = GridView1.SelectedRow;
var query1 = from p in dc.Users
where p.groups.GroupID == Int32.Parse(row.Cells[1].Text)
select new
{
p.Name,
p.Address,
p.Contact Number,
p.Bio,
};
I know that I can use GridView again to display the results of the query, but this doesn't really look nice as it shows too much information at once. How would I go about having some sort of display which will show just one user at a time, giving me the chance to click next and back?
This is what DetailsView is for. However, I would recommend coming up with your own system. Trying to shove the functionality you want into the built-in ASP.NET controls is usually an exercise in frustration.
For this sort of thing what I generally do is have the ID column as an asp:Hyperlink that takes the user to the Details page of whatever data you are showing.
精彩评论