Reputation: 407
I have a ListView and two dropdown controllers in the InsertItemTemplate. Those dropdown lists get their data from another table than the ListViews data.
<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="ObjectDataSource2"
DataTextField="Genrename" DataValueField="GenreID"
SelectedValue='<%# Bind("GenreID") %>'>
</asp:DropDownList>
<br />
<asp:DropDownList ID="DropDownList2" runat="server" DataSourceID="ObjectDataSource3"
DataTextField="Directorname" DataValueField="RegissorID"
SelectedValue='<%# Bind("DirectorID") %>'>
</asp:DropDownList>
I am adding values to the main ListView, but the values I insert in the main table is ID values like, GenreID.
My table looks something like this:
Movie | Genre | Director
James Bond 3 4
Donald Duck 6 13
The Hangover 7 8
Now, i want to display the Names of the Genre and Director instead of the ID's, but i still need to insert the ID's inte my main table (movies).
This is how my ItemTemplate looks like:
<td>
<asp:Label ID="GenreIDLabel" runat="server" Text='<%# Eval("GenreID") %>' />
</td>
<td>
<asp:Label ID="RegissorIDLabel" runat="server" Text='<%# Eval("RegissorID") %>' />
</td>
Upvotes: 0
Views: 444
Reputation: 2689
Modify the SelectCommand
of the datasource control that is being accessed by the ListView.
Join the three tables
Example:
SelectCommand="Select m.movie,m.Genre,m.Director,g.GenreName,d.DirectorName From Movies as m Inner Join Genres as g ON m.Genre=g.GenreID Inner Join Directors as d ON m.Director=d.DirectorID"
After this point GenreName
and DirectorName
are accessible to your gridview.
Update your ItemTemplate
<td>
<asp:Label ID="GenreIDLabel" runat="server" Text='<%# Eval("GenreName") %>' />
</td>
<td>
<asp:Label ID="RegissorIDLabel" runat="server" Text='<%# Eval("DirectorName") %>' />
</td>
Edit I saw in your comment that you're getting the data from a list. I guess it works the same just update your select statement. In my example I assumed you're using SqlDataSource control
Upvotes: 3