0

This is how I should be able to update a product on the page, it must grasp the category which I have chosen, so I will be free to save my choice every time.

I chose to do it via SqlDataSource dropdownlist.

I have written the code like this:

<asp:DropDownList ID="DropDownList1" 
        runat="server" 
        CssClass="form-control" 
        DataSourceID="SqlDataSource1" 
        DataTextField="navn" 
        DataValueField="Id"
        SelectedValue='<%# Bind("kategori") %>'
        ></asp:DropDownList>

    <%--datasource--%>
    <asp:SqlDataSource runat="server" ID="SqlDataSource1" ConnectionString='<%$ ConnectionStrings:ConnectionString %>' 
        SelectCommand="SELECT kategori.id, kategori.navn, produkter.fk_kategori FROM kategori INNER JOIN produkter on kategori.id=produkter.fk_kategori ORDER BY [Id] DESC"></asp:SqlDataSource>

It appears this one error:

Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.

<asp:DropDownList ID="DropDownList1" 

What should I do to the grasp it I've chosen category.

invidicult
  • 306
  • 2
  • 8
  • 19
J Petersen
  • 11
  • 4
  • your selected value must be SelectedValue='<%# Bind("id") %>', why you are using sqldatasource you can bind it manually.. – Rahul Jan 14 '15 at 09:42
  • is your `ddl` is inside any databound control? – صفي Jan 14 '15 at 09:44
  • @Rahul Where can I find a good solution to the task, - Maybe here: http://stackoverflow.com/questions/22945922/gridview-edititemtemplate-dropdownlist-get-selectedvalue – J Petersen Jan 14 '15 at 09:55
  • 1
    Your error message is self explanatory! Also, when you want to show a single value to be selected, are you passing one? No! You are passing the column name of complete query, but it expects a single value. – Rahul Singh Jan 14 '15 at 09:58

0 Answers0