Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NETLINQ
I like to use 1 nested gridview for showing the result like below, column 1 & column 2 are for main gridview and column 3 is for nested gridview.
 
Main gridview , nested gridview are control of an user control.
I like my result was like below:
 TransId Transmittal TranstoCon
     1        TT-0001    TT-CON-0005
                         TT-CON-0100                         
 
     2       TT-0009     TT-CON-3000
but after running , my grid view shows like below (Duplicate records):
TransId         Transmittal             TranstoCon
     1               TT-0001                 TT-CON-0005
                                             TT-CON-0100
                                             TT-CON-3000
 
     1               TT-0001                 TT-CON-0005
                                             TT-CON-0100
                                             TT-CON-3000
 
     1               TT-0001                 TT-CON-0005
                                             TT-CON-0100
                                             TT-CON-3000
 
     2               TT-0009                 TT-CON-0005
                                             TT-CON-0100
                                             
                                             TT-CON-3000
Please help what is the problem .How I can solve it.
The code of user control is like below:
public partial class Transmittallistfortest : System.Web.UI.UserControl
    {
    
    class TransmittaltoConPresentationModel
    {
    	public int TransID { get; set; }
    	public String Transmittal { get; set; }
    	public IEnumerable<tblTranstoCon> TranstoCons { get; set; }
    }
    
    public class tbltransmittalNoEventArgs : EventArgs
    {
    	public int TransmittalId { get; set; }
    }
    
    public event EventHandler<tbltransmittalNoEventArgs> DeleteTransmittal;
    
    private IEnumerable<tbltransmittalNo> _Transmittals;
    
    public IEnumerable<tbltransmittalNo> Transmittals
    {
    	set { _Transmittals = value; }
    }
    
    private IEnumerable<tblTranstoCon> _Transmittaltocons;
    
    public IEnumerable<tblTranstoCon> Transmittaltocons
    {
    	set { _Transmittaltocons = value; }
    }
    
    private IEnumerable<tblDocTranstoCon> _DocTranstoCons;
    
    public IEnumerable<tblDocTranstoCon> DocTranstoCons
    {
    	set { _DocTranstoCons = value; }
    }
    
    public IEnumerable<tblTransmittall> tblTransmittall
    {
    	set;
    	private get;
    }
    public int Doc
    {
    	set;
    	private get;
    }
    
    protected void Page_Load(object sender, EventArgs e)
    {
    
    }
    
    public override void DataBind()
    {
    	base.DataBind();
    	if (_Transmittals != null)
    	{
    		DisplayTransmittals();
    	}
    }
    
    private void DisplayTransmittals()
    {
    	if (_Transmittals != null)
    	{
    
    
    
    		var query = from transmittalno in _Transmittals
    					from Transmittal in tblTransmittall
    					from doctranstocon in _DocTranstoCons
    					from transtocon in _Transmittaltocons
    					where ((transmittalno.TransID ==
    
     Transmittal.TransId) && (Transmittal.TransId == doctranstocon.Transid) && (Transmittal.DocID == doctranstocon.Docid)
    
    					&& (doctranstocon.TransmitToConid == 
    
    transtocon.TRANSMITtoConId))
    
    					select new TransmittaltoConPresentationModel { 
    
    TransID = transmittalno.TransID, Transmittal = 
    
    transmittalno.TRANSMITTAL.ToString(), 
    
    TranstoCons = from x in _Transmittaltocons   select x };
    
    		GridViewTtransmittals.DataSource = query;    		  
    		
    	}
    	else
    	{
    		GridViewTtransmittals.DataSource = null;
    	}
    	GridViewTtransmittals.DataBind();
    }
    
    protected void GridViewTtransmittals_RowDataBound(object sender, GridViewRowEventArgs e)
    {
    	if (e.Row.DataItem == null)
    		return;
    	TransmittaltoConPresentationModel transmittaltoCon = (TransmittaltoConPresentationModel)e.Row.DataItem;
    
    
    	GridView g2 = (GridView)e.Row.FindControl("GridViewTranstoCon");
    
    	g2.DataSource = transmittaltoCon.TranstoCons;
    
    	g2.DataBind();
    }
markup of user control that contain parent gridview and nested gridview is like below:
<pre lang="xml"><%@ Control Language="C#" AutoEventWireup="true" CodeFile="Transmittallistfortest.ascx.cs" Inherits="Transmittallistfortest" %>
            <asp:GridView ID="GridViewTtransmittals" runat="server" AutoGenerateColumns="False"
              BorderStyle="None" ShowHeader="False" Width="100%" DataKeyNames="TransID"  onrowdatabound="GridViewTtransmittals_RowDataBound"
            onrowdeleting="GridViewTtransmittals_RowDeleting">
              <columns>
                <asp:hyperlinkfield DataNavigateUrlFields="TransId"
                  DataNavigateUrlFormatString="~/Copy of Transmittal.aspx?TransId={0}" DataTextField="TRANSMITTAL"
                  HeaderText="Transmittal" />
                <asp:CommandField ButtonType="Button" ShowDeleteButton="true" />
 
    <asp:TemplateField HeaderText = "TRANSMITtoCon">
    <ItemTemplate>
 
                     <asp:GridView ID="GridViewTranstoCon" runat="server" AutoGenerateColumns="False" CellPadding="4"
                        ForeColor="#000000" GridLines="Both">
                 <AlternatingRowStyle BackColor="Yellow" />
                        <Columns>
                          <asp:BoundField DataField="TRANSMITtoCon" HeaderText= "TRANSMITtoCon" >
                           <ItemStyle Width = "20%" />
                          </asp:BoundField>
 
                         </Columns>
                         <EditRowStyle BackColor="#7C6F57" />
             <FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
            <HeaderStyle BackColor="Red" Font-Bold="True" ForeColor="White" />
            <PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />
            <RowStyle BackColor="#E3EAEB" />
            <SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />
                        </asp:GridView>
                    </ItemTemplate>
                </asp:TemplateField>
                 </columns>
 
</asp:GridView>
Posted 6-Oct-12 8:48am
Edited 6-Oct-12 9:05am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 457
1 OriginalGriff 430
2 Shai Vashdi 240
3 Emre Ataseven 165
4 Peter Leow 146
0 Sergey Alexandrovich Kryukov 8,944
1 OriginalGriff 5,280
2 Peter Leow 3,985
3 Maciej Los 3,535
4 Abhinav S 3,218


Advertise | Privacy | Mobile
Web02 | 2.8.140415.2 | Last Updated 6 Oct 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid