Hi
I get the error Invalid column name 'MakerID' from my code below.

<asp:GridView ID="GridView1"  AllowSorting="true" AllowPaging="true" runat="server" DataSourceID="SqlDataSource1"
AutoGenerateDeleteButton="true" AutoGenerateEditButton="true" DataKeyNames="CamID"AutoGenerateColumns="False">
<Columns>
<asp:BoundField Visible="false" ReadOnly="true" HeaderText="ID" DataField="CamID" 	SortExpression="CamID" />
<asp:BoundField HeaderText="Kamera" DataField="CamName" SortExpression="CamName" />
<asp:BoundField HeaderText="MakerID" DataField="MakerID" SortExpression="MakerID" />
<asp:TemplateField HeaderText="Tillverkare">
<EditItemTemplate>
<asp:SqlDataSource SelectCommand="Select * from Maker" ConnectionString="<%$ ConnectionStrings:CamConnString %>"
ID="SqlDSMaker" runat="server"></asp:SqlDataSource>
<asp:DropDownList ID="ddlMaker" runat="server" AppendDataBoundItems="true" DataSourceID="SqlDSMaker"
DataTextField="MakerName" DataValueField="MakerID" AutoPostBack="True" SelectedValue='<%# Eval("MakerID") %>'>
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:SqlDataSource SelectCommand="Select * from Maker" ConnectionString="<%$ ConnectionStrings:CamConnString %>"
ID="SqlDSMaker" runat="server"></asp:SqlDataSource>
<asp:DropDownList ID="ddlMaker1" runat="server" AppendDataBoundItems="true" DataSourceID="SqlDSMaker"
DataTextField="MakerName" DataValueField="MakerID" AutoPostBack="True" SelectedValue='<%# Eval("MakerID") %>'>
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField HeaderText="Megapixels" DataField="MegaPix" SortExpression="MegaPix" />
<asp:BoundField HeaderText="Pris" DataField="Price" SortExpression="Price" />
<asp:BoundField HeaderText="Antal" DataField="Quantity" SortExpression="Quantity" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" SelectCommand="select CamID, CamName,MakerName,MegaPix,Price,Quantity,MakerID from DigCameras,Maker where Maker =MakerID" UpdateCommand="UPDATE [DigCameras] SET [CamName] = @CamName, [MakerID] = @MakerID, [MegaPix] = @MegaPix, [Price] = @Price, [Quantity] = @Quantity WHERE [CamID] = @CamID"
DeleteCommand ="Delete DigCameras where CamID=@CamID"
ConnectionString="<%$ ConnectionStrings:CamConnString %>" >
</asp:SqlDataSource>

I have never used the control GridView before, and I don't know if I have insertred the dropdownlist correctly. But I want to have a dropdownlist for the user to choose the Maker from the table Maker.

Please help me
And if you can explain thorougly, please do, what I need to do to make it work.

Thanks
Fia

Are you using the C# code behind as well ????.......If yes then plz check the MakerID coloumn name in that.........

I believe the problem is with your SelectCommand in SqlDataSource1. you are using two tables in Select Query. It seems like the problem is in Where clause, you have written Maker = MakerID..

I say instead of this write the query like below :

select CamID, CamName,MakerName,MegaPix,Price,Quantity,MakerID from DigCameras,Maker where Maker.MakerID = DigCameras.MakerID

========================================================================================

Hi
I get the error Invalid column name 'MakerID' from my code below.

<asp:GridView ID="GridView1"  AllowSorting="true" AllowPaging="true" runat="server" DataSourceID="SqlDataSource1"
AutoGenerateDeleteButton="true" AutoGenerateEditButton="true" DataKeyNames="CamID"AutoGenerateColumns="False">
<Columns>
<asp:BoundField Visible="false" ReadOnly="true" HeaderText="ID" DataField="CamID" 	SortExpression="CamID" />
<asp:BoundField HeaderText="Kamera" DataField="CamName" SortExpression="CamName" />
<asp:BoundField HeaderText="MakerID" DataField="MakerID" SortExpression="MakerID" />
<asp:TemplateField HeaderText="Tillverkare">
<EditItemTemplate>
<asp:SqlDataSource SelectCommand="Select * from Maker" ConnectionString="<%$ ConnectionStrings:CamConnString %>"
ID="SqlDSMaker" runat="server"></asp:SqlDataSource>
<asp:DropDownList ID="ddlMaker" runat="server" AppendDataBoundItems="true" DataSourceID="SqlDSMaker"
DataTextField="MakerName" DataValueField="MakerID" AutoPostBack="True" SelectedValue='<%# Eval("MakerID") %>'>
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:SqlDataSource SelectCommand="Select * from Maker" ConnectionString="<%$ ConnectionStrings:CamConnString %>"
ID="SqlDSMaker" runat="server"></asp:SqlDataSource>
<asp:DropDownList ID="ddlMaker1" runat="server" AppendDataBoundItems="true" DataSourceID="SqlDSMaker"
DataTextField="MakerName" DataValueField="MakerID" AutoPostBack="True" SelectedValue='<%# Eval("MakerID") %>'>
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField HeaderText="Megapixels" DataField="MegaPix" SortExpression="MegaPix" />
<asp:BoundField HeaderText="Pris" DataField="Price" SortExpression="Price" />
<asp:BoundField HeaderText="Antal" DataField="Quantity" SortExpression="Quantity" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" SelectCommand="select CamID, CamName,MakerName,MegaPix,Price,Quantity,MakerID from DigCameras,Maker where Maker =MakerID" UpdateCommand="UPDATE [DigCameras] SET [CamName] = @CamName, [MakerID] = @MakerID, [MegaPix] = @MegaPix, [Price] = @Price, [Quantity] = @Quantity WHERE [CamID] = @CamID"
DeleteCommand ="Delete DigCameras where CamID=@CamID"
ConnectionString="<%$ ConnectionStrings:CamConnString %>" >
</asp:SqlDataSource>

I have never used the control GridView before, and I don't know if I have insertred the dropdownlist correctly. But I want to have a dropdownlist for the user to choose the Maker from the table Maker.

Please help me
And if you can explain thorougly, please do, what I need to do to make it work.

Thanks
Fia

Hi again

Sorry I didn't explain when the error happens. It's when I'm trying to update after I have edit a row.

Thanks
Fia

Try This..

it contains the code 4 downloading..

hope that helps..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.