<div>i read I can do it in RowDataBount event but not sure how to set it up?</div> <div></div> <div>CountryId is not a column in the Table that Gridview2 is connected to as I use</div> <div>a select query in the DAL to get CountryId from other table</div>
prontonet
Member
243 Points
484 Posts
Trying to add repeater in GridView Template field to return data from another table?
Dec 22, 2012 01:44 AM|LINK
I have a gridview bound to object data source which fetches data from a table in my database.
In the Select Query I have the following which adds another Field to the Gridview column
(SELECT CountryId
FROM Model
WHERE (ModelId = ModelAssignments.ModelId)) AS CountryId,
This adds another Column to the Gridview display "CountryId" and returns an INT
However I want to Display CountryName so I made ColumnId a template field and
put a Repeater in like below
<asp:TemplateField HeaderText="Country" SortExpression="CountryId">
<ItemTemplate>
<asp:Repeater ID="Repeater2" runat="server" DataSourceID="ObjectDataSource5">
<ItemTemplate>
<h1 style="font-size: 3.4em; font-family: Arial, Helvetica, sans-serif; font-weight: normal; font-style: normal; font-variant: normal; text-transform: uppercase;">
<strong>
<asp:Label ID="IntroLabel" runat="server" Text='<%# Eval("CountryName") %>' />
</strong>
</h1>
</ItemTemplate>
</asp:Repeater>
</ItemTemplate>
</asp:TemplateField>
objectdatasource 5 - select parameter
<SelectParameters>
<asp:ControlParameter ControlID="GridView1" Name="CountryId"
PropertyName="SelectedValue" Type="Int32" />
</SelectParameters>
The problem is NOTHING appears and I was expecting the country name
Is this because CountryId is not a true column in the table that Gridview 1 is connected
to and I am adding it as a select - so the parameter is not picked up?
any advice appreciated!
oned_gk
All-Star
30933 Points
6330 Posts
Re: Trying to add repeater in GridView Template field to return data from another table?
Dec 22, 2012 02:29 AM|LINK
Use hiddenfield inside Country template, bind value to CountryId. Place ObjectDataSource5 in same place and use the hiddenfield as control parameter.
prontonet
Member
243 Points
484 Posts
Re: Trying to add repeater in GridView Template field to return data from another table?
Dec 22, 2012 10:54 AM|LINK
not sure I follow exactly could you demonstrate - i heard I could use a databound event as well?
prontonet
Member
243 Points
484 Posts
Re: Trying to add repeater in GridView Template field to return data from another table?
Dec 24, 2012 08:57 AM|LINK
hi,
I am still trying to show the data in Gridview 3 that is placed within Gridview 2 - which expects
parameter of CountryId
<SelectParameters>
<div>i read I can do it in RowDataBount event but not sure how to set it up?</div> <div></div> <div>CountryId is not a column in the Table that Gridview2 is connected to as I use</div> <div>a select query in the DAL to get CountryId from other table</div><Parameter name="CountyId" type=" Int32">
</SelectParameters>
<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False"
DataKeyNames="ModelId,AssignmentId" DataSourceID="ObjectDataSource3"
Width="355px">
<Columns>
<asp:BoundField DataField="FirstName" HeaderText="FirstName"
ReadOnly="True" SortExpression="AssignmentId" />
<asp:BoundField DataField="LastName" HeaderText="LastName"
ReadOnly="True" SortExpression="AssignmentId" />
<asp:BoundField DataField="CountryId" HeaderText="ID"
ReadOnly="True" SortExpression="AssignmentId" />
<asp:TemplateField HeaderText="CountryId"
SortExpression="AssignmentId">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("CountryId") %>'></asp:Label>
<asp:GridView ID="GridView3" runat="server" AutoGenerateColumns="False"
DataKeyNames="CountryId" DataSourceID="ObjectDataSource5">
<Columns>
<asp:BoundField DataField="CountryId" HeaderText="CountryId"
InsertVisible="False" ReadOnly="True" SortExpression="CountryId" />
<asp:BoundField DataField="Sort Order" HeaderText="Sort Order"
SortExpression="Sort Order" />
<asp:BoundField DataField="CommonName" HeaderText="CommonName"
SortExpression="CommonName" />
</Columns>
</asp:GridView>
<asp:ObjectDataSource ID="ObjectDataSource5" runat="server"
OldValuesParameterFormatString="original_{0}" SelectMethod="GetDataByCountryId"
TypeName="DataSet2TableAdapters.CountryTableAdapter">
<SelectParameters>
</SelectParameters>
</asp:ObjectDataSource>
</ItemTemplate>
</asp:TemplateField>
</asp:GridView>
<asp:ObjectDataSource ID="ObjectDataSource3" runat="server"
DeleteMethod="Delete" InsertMethod="Insert"
OldValuesParameterFormatString="original_{0}" SelectMethod="GetDataByModelAssignmentId"
TypeName="DataSet2TableAdapters.ModelAssignmentsTableAdapter"
UpdateMethod="Update">
<SelectParameters>
<asp:QueryStringParameter Name="AssignmentId" QueryStringField="AssignmentId"
Type="Int32" />
</SelectParameters>
</asp:ObjectDataSource>