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>
Modify the
SelectCommandof the datasource control that is being accessed by the ListView.Join the three tablesExample:
After this point
GenreNameandDirectorNameare accessible to your gridview.Update your ItemTemplate
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