Hi,
I am repeatedly getting the same values (Duplicate grouping) when i grouping the recrod project type.
pls.see the code and also Screenshot in the enclosed document.
ASPX Code
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Test_GridViewGroupby.aspx.vb" Inherits="Test_GridViewGroupby" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="AjxTool" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Untitled Page</title>
<link type="text/css" rel="Stylesheet" href="Includes/css/dialog.css" />
<link type="text/css" rel="Stylesheet" href="Includes/css/pager.css" />
<link type="text/css" rel="Stylesheet" href="Includes/css/grid.css" />
</head>
<body>
<form id="form1" runat="server">
<AjxTool:ToolkitScriptManager ID="ScriptManager1" runat="server" />
<%-- <asp:SqlDataSource ID="sqlDsCustomers" runat="server" ConnectionString="<%$ ConnectionStrings:Northwind %>"
SelectCommand="SELECT [Customers].[CustomerID], [Customers].[CompanyName], COUNT([OrderID]) TotalOrdersFROM [Customers] INNER JOIN [Orders] ON [Customers].[CustomerID]=[Orders].[CustomerID]Group By [Customers].[CustomerID], [Customers].[CompanyName]">
--%>
<asp:SqlDataSource ID="sqlDsCustomers" runat="server" ConnectionString="<%$ ConnectionStrings:MPP %>"
SelectCommand="Select ProjectTypeDescription as ProjectTypeDescription,projectno as ProjectNoID,projectname as ProjectName,projectcode as ProjectNumber,duration as Duration,
StartDate as StartWeek,EndDate as EndWeek,ProjectTypeCode as ProjectType,
emp_name+' '+ emp_initial+' - '+emp_number as ProjectLead from csproject LEFT OUTER JOIN
idpeapp.dbo.view_employee on idpeapp.dbo.view_employee.Emp_number=csproject.prjlead
INNER JOIN mppProjectType on csproject.PrjType=mppProjectType.ProjectTypeCode and csproject.PRJTYPE not in(9,11)
order by csproject.PrjListOrder,csproject.projectname">
<asp:Panel CssClass="grid" ID="pnlCust" runat="server">
<asp:UpdatePanel ID="pnlUpdate" runat="server">
<contenttemplate>
<asp:GridView Width="100%" AllowPaging="True" ID="gvCustomers" AutoGenerateColumns="False"
DataSourceID="sqlDsCustomers" runat="server" ShowHeader="False" OnRowCreated="gvCustomers_RowCreated">
<columns> <asp:TemplateField>
<itemtemplate>
<asp:Panel CssClass="group" ID="pnlCustomer" runat="server">
<asp:Image ID="imgCollapsible" CssClass="first" ImageUrl="~/GridImg/plus.png"
Style="margin-right: 5px;" runat="server" />
<asp:SqlDataSource ID="sqlDsOrders" runat="server" ConnectionString="<%$ ConnectionStrings:MPP %>"
SelectCommand="Select projectno as ProjectNoID,projectname as ProjectName,projectcode as ProjectNumber,duration as Duration,
StartDate as StartWeek,EndDate as EndWeek,ProjectTypeCode as ProjectType,
emp_name+' '+ emp_initial+' - '+emp_number as ProjectLead from csproject LEFT OUTER JOIN
idpeapp.dbo.view_employee on idpeapp.dbo.view_employee.Emp_number=csproject.prjlead
INNER JOIN mppProjectType on csproject.PrjType=mppProjectType.ProjectTypeCode and csproject.PRJTYPE not in(9,11) where csproject.PRJTYPE = @ProjectType
order by csproject.PrjListOrder,csproject.projectname">
<SelectParameters>
<asp:Parameter Name="ProjectType" Type="String" DefaultValue="" />
</SelectParameters>
<asp:Panel Style="margin-left: 20px; margin-right: 20px" ID="pnlOrders" runat="server">
<asp:GridView AutoGenerateColumns="false" CssClass="grid" ID="gvOrders" DataSourceID="sqlDsOrders"
runat="server" ShowHeader="true" EnableViewState="false">
<rowstyle cssclass="row">
<alternatingrowstyle cssclass="altrow">
<columns> <asp:TemplateField ItemStyle-CssClass="rownum">
<itemtemplate>
<%# Container.DataItemIndex + 1%>
<asp:BoundField HeaderText="Proposal / Project Name" DataField="ProjectName" ItemStyle-Width="80px" />
<asp:BoundField HeaderText="Project Number" DataField="ProjectNumber"
ItemStyle-Width="100px" />
<asp:BoundField HeaderText="Duration (In Weeks) " DataField="Duration"
ItemStyle-Width="110px" />
<asp:BoundField HeaderText="Start Week" DataField="StartWeek"
ItemStyle-Width="50px" ItemStyle-HorizontalAlign="Right" />
<asp:BoundField HeaderText="End Week" DataField="EndWeek"
ItemStyle-Width="100px" />
<asp:BoundField HeaderText="Proj Lead" DataField="ProjectLead"
ItemStyle-Width="100px" />
<asp:TemplateField HeaderText="Asst.Proj Lead" ItemStyle-HorizontalAlign="Center">
<itemtemplate>
<asp:Button ID="btnAssPrjLead" text="Add" width="50%" runat="server" CommandName="AsstPrjLead" Height="20"
CommandArgument='<%# Eval("ProjectNoID") %>'
/>
<itemstyle horizontalalign="Center" width="2%">
<asp:TemplateField HeaderText="Edit" ItemStyle-HorizontalAlign="Center">
<itemtemplate>
<asp:HyperLink ID="hyperlink1" runat="server" Height="20"
ImageUrl="~/images/Access.gif"
Width="20" />
<itemstyle horizontalalign="Center" width="2%">
<asp:TemplateField HeaderText="Delete" ItemStyle-HorizontalAlign="Center">
<itemtemplate>
<asp:ImageButton ID="btnDelete" runat="server" CommandName="Delete" Height="20"
ImageUrl="~/images/btn_Delete.gif"
CommandArgument='<%# Eval("ProjectNoID") %>'
Width="20" />
<itemstyle horizontalalign="Center" width="2%">
<AjxTool:collapsiblepanelextender ID="cpe" runat="server" targetcontrolid="pnlOrders"
collapsedsize="0" collapsed="True" expandcontrolid="pnlCustomer" collapsecontrolid="pnlCustomer"
autocollapse="False" autoexpand="False" scrollcontents="false" imagecontrolid="imgCollapsible"
expandedimage="~/GridImg/minus.png" collapsedimage="~/GridImg/plus.png"
expanddirection="Vertical" />
</form>
</body>
</html>
Aspx.vb Code
************
Imports System.Data
Imports System.Configuration
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Web.UI.HtmlControls
Partial Class Test_GridViewGroupby
Inherits System.Web.UI.Page
Protected Sub gvCustomers_RowCreated(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
If e.Row.RowType = DataControlRowType.DataRow Then
Dim ctrl As SqlDataSource = TryCast(e.Row.FindControl("sqlDsOrders"), SqlDataSource)
If ctrl IsNot Nothing AndAlso e.Row.DataItem IsNot Nothing Then
ctrl.SelectParameters("ProjectType").DefaultValue = DirectCast(e.Row.DataItem, DataRowView)("ProjectType").ToString()
End If
End If
End Sub
End Class
pls. provide me the correct solution where i did the mistake.
Regards,
Ganesh.S