I have a table that has two columns:
CommunityID
PersonID
And A “People” table that has (among other things):
FirstName
LastName
I would like to display a different DataGrid for each community, each datagrid having only the people that are part of that community. I would like to do this without using 4 seperate SqlDataSources.
A Repeater looks like a good way, with a DataGrid inside the ItemTemplate, but I can’t seem to make heads or tails of getting that to work with the different values for each repetition.
If anyone has any suggestions on better ways to do this, I’d be very appreciative, as this is one of my first forays into the world for ASP.NET
Thanks,
Mike
Personally I wouldn’t use a DataGrid control, since it restricts your control over your output and they’ve been replaced by the newer
GridView&ListViewcontrols (although DataGrid is not obsolete so feel free to use it if you want). You may want to consider using the alternatives but you aren’t required to do so.To do what you’re looking for, you would have markup like the following:
Then you’ll wire up the markup with the following code-behind:
The key is the Repeater’s
ItemDataBoundevent, which is the method called every time a repeater row is created. This is where you can data bind your DataGrid source. You can put any logic you need to within this method using theRepeaterItemEventArgsparameter to access the data item you bound to your Repeater.