You must Sign In to post a response.
  • Category: ASP.NET

    merge three gridview and show it in a sinle gridview in asp.net

    merge three gridview and show it in a sinle gridview in asp.net


    my source

    <table class="style1" align="center" style="border: thin outset #1d599e; width: 100%; margin-left: 0px; background-color:White;">
    <tr><td style="margin-left: 50px; background:white;" align="center">
    <asp:Label ID="Selt" runat="server" Font-Bold="True" Font-Italic="True"
    Font-Size="Larger" Text="Selected Party Details "></asp:Label>
    </td></tr><tr><td>
    <asp:Label ID="sysdt" runat="server" Visible="False"></asp:Label>
    <asp:Label ID="Lcurentsys" runat="server"></asp:Label>
    </td></tr>
    <tr><td></td></tr>
    <tr><td align="center">
    <asp:GridView ID="GridView4" runat="server" CellPadding="4" AutoGenerateColumns="false"
    GridLines="None" ForeColor="#333333">
    <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
    <FooterStyle BackColor="#5D7B9D" ForeColor="White" Font-Bold="True" />
    <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
    <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
    <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
    <Columns>
    <asp:TemplateField ControlStyle-Width="150px" ItemStyle-HorizontalAlign="Center" ItemStyle-Width="120px" ControlStyle-Font-Bold="true" HeaderText="Partyname">
    <ItemTemplate>
    <asp:Label ID="partyn" runat="server" Text="<%#bind('partyname')%>"></asp:Label>
    </ItemTemplate>
    <ControlStyle Font-Bold="True" Width="150px" />
    <ItemStyle Width="120px" />
    </asp:TemplateField>

    <asp:TemplateField HeaderText="Bill Date" ControlStyle-Width="150px" ItemStyle-Width="120px" ControlStyle-Font-Bold="true" ItemStyle-HorizontalAlign="Center">
    <ItemTemplate>
    <asp:Label ID="LLaDt" runat="server" Text="<%# bind('date') %>"></asp:Label>
    </ItemTemplate>
    <ControlStyle Font-Bold="True" Width="150px" />
    <ItemStyle Width="120px" />
    </asp:TemplateField>

    <%-- <asp:TemplateField HeaderText="Vat" ControlStyle-Width="150px" ItemStyle-Width="120px" ControlStyle-Font-Bold="true" ItemStyle-HorizontalAlign="Center" Visible="false">
    <ItemTemplate>
    <asp:Label ID="LLVAT" runat="server" Text="<%# bind('vat') %>"></asp:Label>
    </ItemTemplate>
    <ControlStyle Font-Bold="True" Width="150px" />
    <ItemStyle Width="120px" />
    </asp:TemplateField>


    <asp:TemplateField HeaderText="Discount" ControlStyle-Width="150px" ItemStyle-Width="120px" ControlStyle-Font-Bold="true" ItemStyle-HorizontalAlign="Center" Visible="false">
    <ItemTemplate>
    <asp:Label ID="LLDIS" runat="server" Text="<%# bind('discount') %>"></asp:Label>
    </ItemTemplate>
    <ControlStyle Font-Bold="True" Width="150px" />
    <ItemStyle Width="120px" />
    </asp:TemplateField>
    --%>

    <asp:TemplateField HeaderText="Amount" ControlStyle-Width="120px" ItemStyle-Width="100px" ControlStyle-Font-Bold="true" ItemStyle-HorizontalAlign="Center">
    <ItemTemplate>
    <asp:Label ID="LLBILAMT" runat="server" Text="<%#bind('billamount') %>"></asp:Label>
    </ItemTemplate>
    <ControlStyle Width="120px" />
    <ItemStyle Width="100px" />
    <FooterTemplate>
    <asp:Label ID="bilamt" runat="server" />
    </FooterTemplate>
    </asp:TemplateField>

    </Columns>










    <EditRowStyle BackColor="#999999" />
    <AlternatingRowStyle BackColor="White" ForeColor="#284775" />










    </asp:GridView></td></tr>

    <tr><td>
    <asp:GridView ID="GridView5" runat="server" BackColor="White"
    BorderColor="#336666" BorderStyle="Double" BorderWidth="3px" CellPadding="4"
    GridLines="Horizontal">
    <RowStyle BackColor="White" ForeColor="#333333" />
    <FooterStyle BackColor="White" ForeColor="#333333" />
    <PagerStyle BackColor="#336666" ForeColor="White" HorizontalAlign="Center" />
    <SelectedRowStyle BackColor="#339966" Font-Bold="True" ForeColor="White" />
    <HeaderStyle BackColor="#336666" Font-Bold="True" ForeColor="White" />
    <Columns>
    <asp:TemplateField HeaderText="Sectionname" ControlStyle-Width="120px" ItemStyle-Width="100px" ControlStyle-Font-Bold="true" ItemStyle-HorizontalAlign="Center">
    <ItemTemplate>
    <asp:Label ID="NewILAMT" runat="server" Text="<%#bind('sectionname') %>"></asp:Label>
    </ItemTemplate>
    <ControlStyle Width="120px" />
    <ItemStyle Width="100px" />
    <FooterTemplate>
    <asp:Label ID="bilamt" runat="server" />
    </FooterTemplate>
    </asp:TemplateField>

    <asp:TemplateField HeaderText="Partyname" ControlStyle-Width="120px" ItemStyle-Width="100px" ControlStyle-Font-Bold="true" ItemStyle-HorizontalAlign="Center" Visible="false">
    <ItemTemplate>
    <asp:Label ID="NewPaAMT" runat="server" Text="<%#bind('expensesname') %>"></asp:Label>
    </ItemTemplate>
    <ControlStyle Width="120px" />
    <ItemStyle Width="100px" />
    <FooterTemplate>
    <asp:Label ID="bilamt" runat="server" />
    </FooterTemplate>
    </asp:TemplateField>

    <asp:TemplateField HeaderText="Billno" ControlStyle-Width="120px" ItemStyle-Width="100px" ControlStyle-Font-Bold="true" ItemStyle-HorizontalAlign="Center">
    <ItemTemplate>
    <asp:Label ID="NewBNMT" runat="server" Text="<%#bind('billno') %>"></asp:Label>
    </ItemTemplate>
    <ControlStyle Width="120px" />
    <ItemStyle Width="100px" />
    <FooterTemplate>
    <asp:Label ID="bilamt" runat="server" />
    </FooterTemplate>
    </asp:TemplateField>

    <asp:TemplateField HeaderText="billamount" ControlStyle-Width="120px" ItemStyle-Width="100px" ControlStyle-Font-Bold="true" ItemStyle-HorizontalAlign="Center">
    <ItemTemplate>
    <asp:Label ID="NewBNMT" runat="server" Text="<%#bind('billamount') %>"></asp:Label>
    </ItemTemplate>
    <ControlStyle Width="120px" />
    <ItemStyle Width="100px" />
    <FooterTemplate>
    <asp:Label ID="bilamt" runat="server" />
    </FooterTemplate>
    </asp:TemplateField>

    <asp:TemplateField HeaderText="billamount" ControlStyle-Width="120px" ItemStyle-Width="100px" ControlStyle-Font-Bold="true" ItemStyle-HorizontalAlign="Center">
    <ItemTemplate>
    <asp:Label ID="NeDART" runat="server" Text="<%#bind('date') %>"></asp:Label>
    </ItemTemplate>
    <ControlStyle Width="120px" />
    <ItemStyle Width="100px" />
    <FooterTemplate>
    <asp:Label ID="bilamt" runat="server" />
    </FooterTemplate>
    </asp:TemplateField>

    </Columns>
    </asp:GridView>
    </td></tr>


    <tr><td>

    <asp:GridView ID="GridView6" runat="server" BackColor="White"
    BorderColor="#DEDFDE" BorderStyle="None" BorderWidth="1px" CellPadding="4"
    ForeColor="Black" GridLines="Vertical">
    <RowStyle BackColor="#F7F7DE" />
    <FooterStyle BackColor="#CCCC99" />
    <PagerStyle BackColor="#F7F7DE" ForeColor="Black" HorizontalAlign="Right" />
    <SelectedRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" />
    <HeaderStyle BackColor="#6B696B" Font-Bold="True" ForeColor="White" />
    <AlternatingRowStyle BackColor="White" />
    </asp:GridView>
    <br />
                                                                                           
    <asp:Button ID="Button22" runat="server" onclick="Button22_Click" Text="Next"
    Width="334px" />
    </td></tr>

    <tr><td>
    <asp:GridView ID="GridView7" runat="server">
    <Columns>
    <asp:TemplateField ControlStyle-Width="150px" ItemStyle-HorizontalAlign="Center" ItemStyle-Width="120px" ControlStyle-Font-Bold="true" HeaderText="BillNo">
    <ItemTemplate>
    <asp:Label ID="pbillno" runat="server" Text="<%#bind('billno')%>"></asp:Label>
    </ItemTemplate>
    <ControlStyle Font-Bold="True" Width="150px" />
    <ItemStyle Width="120px" />
    </asp:TemplateField>

    <asp:TemplateField HeaderText="Bill Date" ControlStyle-Width="150px" ItemStyle-Width="120px" ControlStyle-Font-Bold="true" >
    <ItemTemplate>
    <asp:Label ID="LafterreturnLaDt" runat="server" Text="<%# bind('afterreturn') %>"></asp:Label>
    </ItemTemplate>
    <ControlStyle Font-Bold="True" Width="150px" />
    <ItemStyle Width="120px" />
    </asp:TemplateField>

    <asp:TemplateField HeaderText="details" ControlStyle-Width="150px" ItemStyle-Width="120px" ControlStyle-Font-Bold="true" ItemStyle-HorizontalAlign="Center" Visible="false">
    <ItemTemplate>
    <asp:Label ID="LLdetailsT" runat="server" Text="<%# bind('details') %>"></asp:Label>
    </ItemTemplate>
    <ControlStyle Font-Bold="True" Width="150px" />
    <ItemStyle Width="120px" />
    </asp:TemplateField>




    </Columns>
    </asp:GridView>
    </td></tr>

    </table>





    my code


    protected void LBView_Click(object sender, EventArgs e)
    {
    try
    {
    GridViewRow row = GridView3.SelectedRow;
    GridViewRow selectrow = ((LinkButton)sender).NamingContainer as GridViewRow;
    DataSet deset = new DataSet();
    DataSet det = new DataSet();
    DataSet newset = new DataSet();

    con = new SqlConnection(s);
    con.Open();
    {
    MultiView1.SetActiveView(View17);
    Label fet = (Label)selectrow.FindControl("LBN");
    Label sectnn = (Label)selectrow.FindControl("lsn");

    GridViewRow rw = GridView3.SelectedRow;
    string ft = "select partyname,billamount,convert(nvarchar,date,103) as date from partypaymentdetails where billno='" + fet.Text + "'and sectionname='" + sectnn.Text + "'";
    cmd = new SqlCommand(ft, con);
    SqlDataAdapter dew = new SqlDataAdapter(cmd);

    dew.Fill(deset);
    GridView4.DataSource = deset;
    GridView4.DataBind();
    cmd.ExecuteNonQuery();



    Label feat = (Label)selectrow.FindControl("LBN");
    Label seactnn = (Label)selectrow.FindControl("lsn");

    GridViewRow rqw = GridView3.SelectedRow;
    string sft = "select billno,afterreturn,details from stockreturn where billno='" + feat.Text + "'and sectionname='" + seactnn.Text + "'";
    cmd = new SqlCommand(sft, con);
    SqlDataAdapter dssew = new SqlDataAdapter(cmd);

    dssew.Fill(newset);
    GridView7.DataSource = newset;
    GridView7.DataBind();
    cmd.ExecuteNonQuery();

    Label feet = (Label)selectrow.FindControl("LBN");
    Label seeecct = (Label)selectrow.FindControl("lsn");
    Label partty = (Label)selectrow.FindControl("LPM");

    string frst = "select sectionname,expensesname,billno, billamount,date from expenzsection where billno='" + feet.Text + "' and sectionname='" + seeecct.Text + "' and expensesname='" + partty.Text + "'";
    cmd = new SqlCommand(frst, con);
    SqlDataAdapter dsew = new SqlDataAdapter(cmd);

    dsew.Fill(deset);

    det.Merge(newset);
    det.AcceptChanges();
    GridView6.DataSource = det;
    GridView6.DataBind();

    cmd.ExecuteNonQuery();
    con.Close();

    }

    }
    catch (Exception)
    {
    }

    }
    protected void GridView3_RowCommand(object sender, GridViewCommandEventArgs e)
    {
    if (e.CommandName.Equals("View"))
    {
    con = new SqlConnection("Data Source=.\\SQLEXPRESS;Initial Catalog=bramandam;Persist Security Info=True;Integrated Security=True");
    con.Open();
    {

    DataSet newset = new DataSet();
    DataSet det = new DataSet();
    GridViewRow sqr = ((LinkButton)e.CommandSource).NamingContainer as GridViewRow;
    Label lkg = (Label)sqr.FindControl("LBN");

    MultiView1.SetActiveView(View17);
    Label fet = (Label)sqr.FindControl("LBN");
    Label secct = (Label)sqr.FindControl("lsn");
    Label part = (Label)sqr.FindControl("LPM");
    string prtydata = sqr.Cells[0].Text;
    GridViewRow rw = GridView3.SelectedRow;
    string ft = "select partyname,billamount,convert(nvarchar,date,103) as date from partypaymentdetails where billno='" + fet.Text + "' and partyname='" + part.Text + "' and sectionname='" + secct.Text + "'";
    cmd = new SqlCommand(ft, con);
    SqlDataAdapter dew = new SqlDataAdapter(cmd);
    DataSet deset = new DataSet();
    dew.Fill(deset);
    GridView4.DataSource = deset;
    GridView4.DataBind();

    GridViewRow rqaw = GridView3.SelectedRow;





    string sft = "select billno,afterreturn,details from stockreturn where billno='" + fet.Text + "'and sectionname='" + secct.Text + "'";
    cmd = new SqlCommand(sft, con);
    SqlDataAdapter dssew = new SqlDataAdapter(cmd);
    dssew.Fill(newset);
    cmd.ExecuteNonQuery();















    string frst = "select sectionname,expensesname,billno,billamount,date from expenzsection where billno='" + fet.Text + "' and sectionname='" + secct.Text + "'and expensesname='" + part.Text + "'";
    cmd = new SqlCommand(frst, con);
    SqlDataAdapter dehw = new SqlDataAdapter(cmd);
    dehw.Fill(deset);
    det.Merge(deset);
    det.AcceptChanges();
    GridView6.DataSource = det;
    GridView6.DataBind();

    cmd.ExecuteNonQuery();
    con.Close();

    }
    }
    }
  • #763754
    Hi Selvi,

    Rather than merge Gridviews I suggested you to merge your DataTables and bind it into Single Gridview


    dt1.Merge(dt2);
    dt1.Merge(dt3);

    Now, In dt1 having all the records which are available in datatable 2 and datatable 3.

    Note: While merge you need to remember onething both the fields should be same.

    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/

  • #763755
    Hai Selvi,
    The best way is to create a data table which will have the result of all 3 gridview data and then display it in to one gridview just by binding it.
    It should be easy to do by this way.
    Hope it will be helpful to you.

    Regards,
    Pawan Awasthi(DNS MVM)
    +91 8123489140 (whatsApp), +60 14365 1476(Malaysia)
    pawansoftit@gmail.com

  • #763792
    i have three table

    1. partypayment

    2.daily expenses

    3.retrunstockdetils


    in a grid i have one link button i need to show like this

    Sectionname billno billamount billdate details

    Saree 158 1,50,000 08/12/2015 NotPaid(Partyment)

    Saree 158 50,000 10/12/2015 Return (retrunstockdetails)

    Saree 158 50,000 12/12/2015 Paid(Daily Expenses Table)

  • #763829
    Looking at your scenario you need to loop on each gridview and create a single datable and then you can bind that data table to your gridview
    Thanks
    Koolprasd2003
    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]

  • #763831
    You can union three table and get the result in a single data table and assign the value in the single gridview


    select Sectionname, billno, billamount, billdate, 'NotPaid' as details
    from partypayment

    union

    select Sectionname, billno, billamount, billdate, 'Return' as details
    from retrunstockdetails

    union

    select Sectionname, billno, billamount, billdate, 'Paid' as details
    from dailyexpenses

    The above query will help you to get all the data together

    By Nathan
    Direction is important than speed


Sign In to post your comments