briancapetown
New Member
I have 3 tables: CarBrand, CarType and CarModel. I use a gridview to display Carmodel with the FK's of carbrand and cartype as their description not ID. (e.g Mercedes in stead of id 1)When I try to edit and update this gridview I use a dropdown with a display of the title, and as selectedvalue the ID. Then when I click update, the gridview doesn't respond. I know it is a problem with the FK's because it works like a charm without them.Code gridview:\[code\]<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" DataKeyNames="Car_Model_id" AllowPaging="True" CellPadding="4" ForeColor="#333333" GridLines="None"> <AlternatingRowStyle BackColor="White" ForeColor="#284775" /> <Columns> <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" /> <asp:BoundField DataField="car_model" HeaderText="car_model" SortExpression="car_model" /> <asp:BoundField DataField="Car_Model_id" HeaderText="Car_Model_id" SortExpression="Car_Model_id" InsertVisible="False" ReadOnly="True" /> <asp:BoundField DataField="Doors" HeaderText="Doors" SortExpression="Doors" /> <asp:BoundField DataField="Fuel" HeaderText="Fuel" SortExpression="Fuel" /> <asp:BoundField DataField="Seats" HeaderText="Seats" SortExpression="Seats" /> <asp:BoundField DataField="Color" HeaderText="Color" SortExpression="Color" /> <asp:BoundField DataField="Horsepower" HeaderText="Horsepower" SortExpression="Horsepower" /> <asp:TemplateField HeaderText="Car_Brand" SortExpression="Car_Brand"> <EditItemTemplate> <aspropDownList ID="DropDownList1" runat="server" DataSourceID="ObjectDataSourceShowBrand" DataTextField="Car_Brand" DataValueField="Car_Brand_ID"> </aspropDownList> <asp:ObjectDataSource ID="ObjectDataSourceShowBrand" runat="server" SelectMethod="selectAll" TypeName="BLLbrand"></asp:ObjectDataSource> </EditItemTemplate> <ItemTemplate> <asp:Label ID="Label1" runat="server" Text='<%# Bind("Car_Brand") %>'></asp:Label> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Car_Type" SortExpression="Car_Type"> <EditItemTemplate> <aspropDownList ID="DropDownList2" runat="server" DataSourceID="ObjectDataSourceShowType" DataTextField="Car_Type" DataValueField="Car_Type_ID"> </aspropDownList> <asp:ObjectDataSource ID="ObjectDataSourceShowType" runat="server" SelectMethod="selectAll" TypeName="BLLtype"></asp:ObjectDataSource> </EditItemTemplate> <ItemTemplate> <asp:Label ID="Label2" runat="server" Text='<%# Bind("Car_Type") %>'></asp:Label> </ItemTemplate> </asp:TemplateField> <asp:HyperLinkField HeaderText="Maintenance Scheme" Text="View" DataNavigateUrlFields="Car_Model_id" DataNavigateUrlFormatString="viewMaintenanceScheme.aspx?carmodel_id={0}" /> </Columns> <EditRowStyle BackColor="#999999" /> <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" /> <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" /> <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" /> <RowStyle BackColor="#F7F6F3" ForeColor="#333333" /> <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" /> <SortedAscendingCellStyle BackColor="#E9E7E2" /> <SortedAscendingHeaderStyle BackColor="#506C8C" /> <SortedDescendingCellStyle BackColor="#FFFDF8" /> <SortedDescendingHeaderStyle BackColor="#6F8DAE" /> </asp:GridView>\[/code\]Code SQLdatasource:\[code\]<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:CarsConnectionString %>" SelectCommand="SELECT tbl_Car_model.car_model, tbl_Car_model.Car_Model_id, tbl_Car_model.Doors, tbl_Car_model.Fuel, tbl_Car_model.Seats, tbl_Car_model.Color, tbl_Car_model.Horsepower, tbl_Car_Brand.Car_Brand, tbl_Car_type.Car_Type FROM tbl_Car_Brand INNER JOIN tbl_Car_model ON tbl_Car_Brand.Car_Brand_Id = tbl_Car_model.car_brand INNER JOIN tbl_Car_type ON tbl_Car_model.Car_type = tbl_Car_type.Car_Type_id" DeleteCommand="DELETE FROM tbl_Car_model WHERE (Car_Model_id = @car_Model_id)" InsertCommand="INSERT INTO tbl_Car_model(car_model, Doors, Fuel, Seats, Color, Car_type, Horsepower, car_brand, image) VALUES (@car_model, @Doors, @Fuel, @Seats, @Color, @Car_type, @Horsepower, @car_brand, @image)" UpdateCommand="UPDATE tbl_Car_model SET car_model = @car_model, Doors = @Doors, Fuel = @Fuel, Seats = @Seats, Color = @Color, Horsepower = @Horsepower, Car_Brand = @Car_Brand, Car_Type = @Car_Type WHERE (Car_Model_id = @Car_Model_id)"> <DeleteParameters> <asparameter Name="car_Model_id" /> </DeleteParameters> <InsertParameters> <asparameter Name="car_model" /> <asparameter Name="Doors" /> <asparameter Name="Fuel" /> <asparameter Name="Seats" /> <asparameter Name="Color" /> <asparameter Name="Car_type" /> <asparameter Name="Horsepower" /> <asparameter Name="car_brand" /> <asparameter Name="image" /> </InsertParameters> <UpdateParameters> <asparameter Name="car_model" /> <asparameter Name="Doors" /> <asparameter Name="Fuel" /> <asparameter Name="Seats" /> <asparameter Name="Color" /> <asparameter Name="Horsepower" /> <asparameter Name="Car_Model_id" /> <asparameter Name="Car_Brand" Type="Int32" /> <asparameter Name="Car_Type" Type="Int32" /> </UpdateParameters> </asp:SqlDataSource>\[/code\]Could someone please help me, this is driving me crazy!