Hello All,
I want to make a Gridview with a default grouping. For example i have 2 tables. The first one includes Countries and Country IDs. The second contains ID, ContactName, Email, CountryID.
I have 3 Country record in my Countries table and 5 Contact record in my Contacts table. 3 of my contacts belong to CountryID 1 and 2 of them to CountryID 2. There is no contacts for CountryID 3.
I want to group my grid by countries and show all the 3 country and contacts below.
The second condition is i want to be able to move this contacts between this groups. (Of course the records will be updated)
A sample view of my finish work is attached. I get all my countries by grouping in SQL Query. Bu the mistake is i get 1 record for the empty Country record. It souldnt.
My SQL Query is like:
I want to make a Gridview with a default grouping. For example i have 2 tables. The first one includes Countries and Country IDs. The second contains ID, ContactName, Email, CountryID.
I have 3 Country record in my Countries table and 5 Contact record in my Contacts table. 3 of my contacts belong to CountryID 1 and 2 of them to CountryID 2. There is no contacts for CountryID 3.
I want to group my grid by countries and show all the 3 country and contacts below.
The second condition is i want to be able to move this contacts between this groups. (Of course the records will be updated)
A sample view of my finish work is attached. I get all my countries by grouping in SQL Query. Bu the mistake is i get 1 record for the empty Country record. It souldnt.
My SQL Query is like:
SELECT Contacts.ID, Contacts.ContactName, Contacts.Email, Countries.ID AS CountryID, Countries.CountryName, COUNT(Contacts.ID) AS TotalContacts
FROM Contacts RIGHT OUTER JOIN Countries ON Contacts.CountryID = Countries.ID
GROUP BY Contacts.CountryID, Countries.ID, Countries.CountryName, Contacts.ContactName, Contacts.Email, Contacts.ID
<telerik:RadGrid ID="RadGrid1" runat="server" DataSourceID="SqlData" AutoGenerateColumns="False" AllowSorting="True" AllowMultiRowSelection="False" AllowPaging="True" PageSize="15" GridLines="None" OnRowDrop="RadGrid1_RowDrop"> <PagerStyle Mode="NumericPages"></PagerStyle> <MasterTableView DataSourceID="SqlData" DataKeyNames="ID" GroupLoadMode="Server"> <GroupByExpressions> <telerik:GridGroupByExpression> <SelectFields> <telerik:GridGroupByField FieldAlias="Country" FieldName="Country"></telerik:GridGroupByField> <telerik:GridGroupByField FieldName="TotalContact" Aggregate="Count"></telerik:GridGroupByField> </SelectFields> <GroupByFields> <telerik:GridGroupByField FieldName="Country"></telerik:GridGroupByField> </GroupByFields> </telerik:GridGroupByExpression> </GroupByExpressions> <Columns> <telerik:GridDragDropColumn HeaderStyle-Width="18px" /> <telerik:GridBoundColumn SortExpression="ID" HeaderText="ID" HeaderButtonType="TextButton" datafield="ID" UniqueName="ID" /> <telerik:GridBoundColumn SortExpression="ContactName" HeaderText="Name" HeaderButtonType="TextButton" datafield="ContactName" UniqueName="ContactName" /> <telerik:GridBoundColumn SortExpression="Country" HeaderText="Country" HeaderButtonType="TextButton" DataField="Country" UniqueName="Country" /> </Columns> </MasterTableView> <ClientSettings AllowRowsDragDrop="true"> <Selecting AllowRowSelect="True" EnableDragToSelectRows="false" /> </ClientSettings> </telerik:RadGrid>