display two tables data in a single gridvew using asp.net

Posted by Mandlaa under ASP.NET on 11/27/2012 | Points: 10 | Views : 6906 | Status : [Member] | Replies : 3
display two tables data in a single gridvew using asp.net
Not for all columns Some columns only,
PLZ GIVE ME Example,
I am trying using LINQ but not showing the gridview data,

<html>
<head runat="server">

</head>
<Body>
<asp:GridView ID="GridView1" runat="server">
</asp:GridView>
</Body>
</html>

.CS
devdbDataContext dc = new devdbDataContext();
GridView1.DataSource = from c in dc.CONSUMERs join t in dc.TagTables on c.Party_Dim_Key equals t.ConsumerId select new { c.Customer_First_Nm, c.Customer_Last_Nm, t.PhoneNumber, t.Tag_tapped_Date_and_Time };




Responses

Posted by: Pratyupalati on: 11/28/2012 [Member] Starter | Points: 25

Up
0
Down
Hi,
Refer this, it may help you....
you should query your two tables using JOIN to get one result and bind it to datagrid
http://technet.microsoft.com/en-us/library/ms174854.aspx
(or)
You can create a third data table with the required columns and add all the data in both the data tables and bind the new data table to the grid view.
http://www.dotnetperls.com/datatable

Mandlaa, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Oswaldlily on: 11/29/2012 [Member] Starter | Points: 25

Up
0
Down
<asp:TemplateField HeaderText="LiteralID" SortExpression="LiteralID">
<HeaderTemplate>
<asp:LinkButton ID="lnkGroup" runat="server" CommandName="Sort"
Height="10" Font-Underline="false" ForeColor="white" Width="400" Text="<%$ Resources:DefaultResource, LiteralID %>"
ToolTip="<%$ Resources:DefaultResource, ClicktoSort%>"></asp:LinkButton>
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="lblId" runat="server" Style="word-break: break-all; word-wrap: break-word;"
Text='<%# Eval("Column1Table1") %>' Width="400px"></asp:Label>
</ItemTemplate>

</asp:TemplateField>
<asp:TemplateField HeaderText="<%$ Resources:DefaultResource,LiteralEnglishDesc%>"
SortExpression="AD_Lit">
<EditItemTemplate>
<asp:TextBox ID="txtEditEnglish" runat="server" Text='<%# Eval("Column1Table2") %>'
Width="400px"></asp:TextBox>
<asp:RequiredFieldValidator ID="reed" runat="server" ValidationGroup="Update" ErrorMessage="Required" ControlToValidate="txtEditEnglish"></asp:RequiredFieldValidator>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtEnglish" runat="server" ToolTip="<%$ Resources:DefaultResource,InsertnewRecords%>"
Width="400px"></asp:TextBox>
</FooterTemplate>

<ItemTemplate>
<asp:Label ID="lblEnglish" runat="server" CssClass="test" Style="word-break: break-all;
word-wrap: break-word;" Text='<%# Eval("Column1Table2") %>' Width="400px"></asp:Label>
</ItemTemplate>
</asp:TemplateField>

Mandlaa, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Hariinakoti on: 11/29/2012 [Member] Starter | Points: 25

Up
0
Down
Hi,
Using Joins we can display two tables data in single gridview.U can try like that.

Thanks & Regards
Hari

Mandlaa, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response