Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Dears,
I have grid view which get data from sql data source,
and one column are foreign key so i made another sql Data source to get the value,

Every thing work fine (getting data and select) except updating the value in drop down list in edit mode,

here is summary of my code:
Main Data Source (Airport Buildings):
ASP.NET
<asp:SqlDataSource ID="SqlDataSource1">
 <UpdateParameters>
 <asp:Parameter Name="AirportID" Type="Int32"   />
 <asp:Parameter Name="BuildingID" Type="Int32" />
 <asp:Parameter Name="BuildingName" Type="String" />
 <asp:Parameter Name="Description" Type="String" />
 </UpdateParameters>
</asp:SqlDataSource>

Source of Lookup tabel:
 <asp:SqlDataSource ID="sdsAirports"/>


column of Grid View with DataSourceID="SqlDataSource1" :
ASP.NET
  <asp:TemplateField HeaderText="AirportID" SortExpression="AirportID" >
<EditItemTemplate>
<asp:DropDownList ID="DropDownList1"  runat="server"  DataSourceID="sdsAirports" DataTextField="AirportName" DataValueField="AirportID"  SelectedValue='<%# Eval("AirportID").ToString() %>' >
</asp:DropDownList>
                                
</EditItemTemplate>
<ItemTemplate>
<asp:DropDownList ID="DropDownList11" runat="server" DataSourceID="sdsAirports" DataTextField="AirportName" DataValueField="AirportID" SelectedValue='<%# Eval("AirportID").ToString() %>' Enabled="false">
 </asp:DropDownList>
 <%--<asp:Label ID="Label1" runat="server" Text='<%# Bind("AirportName") %>'></asp:Label>--%>
</ItemTemplate>
                           
</asp:TemplateField>

 <asp:TemplateField HeaderText="BuildingName" SortExpression="BuildingName">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("BuildingName") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Bind("BuildingName") %>'></asp:Label>
</ItemTemplate>

</asp:TemplateField>
Posted
Updated 20-Aug-15 1:26am
v2

Try setting the SelectedValue as well SelectedText of the drop down
 
Share this answer
 
The issue in my grid view i have key for the same field and it seems that the same data send to stored procedure so no changes.

alhamdullah
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900