Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8208065
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T09:12:52+00:00 2026-06-07T09:12:52+00:00

I have a gridview. In this i have a templatefield with a DropDownList (DDL

  • 0

I have a gridview. In this i have a templatefield with a DropDownList (DDL in EditItemTemplate mode, label in ItemTemplate mode).
When i hit edit on of of the detailsview’s rows i can select any value from the DDL (the DDL is populated from a sqldatasource), but if i try to execute the update, it fails, because it thinks i didn’t supply the data…

Here is the exact error (the DB refuse NULL data):

Cannot insert the value NULL into column ‘status’, table
‘gyumolcs.dbo.orders’; column does not allow nulls. UPDATE fails. The
statement has been terminated.

Here is the code for the gridview:

<!-- language: c# -->
<asp:SqlDataSource ID="orderadminSqlDataSource" runat="server" 
    ConnectionString="<%$ ConnectionStrings:dotnetConnectionString %>" 
    SelectCommand="SELECT orders.ID, aspnet_Users.UserName, orders.quantity AS Quantity, product.name AS Product, status.name AS Status, orders.date AS Date FROM orders INNER JOIN product ON orders.ordertype = product.ID INNER JOIN status ON orders.status = status.ID INNER JOIN aspnet_Users ON orders.userid = aspnet_Users.UserId ORDER BY date" 
    DeleteCommand="DELETE FROM orders WHERE (ID = @ID)" 
    UpdateCommand="UPDATE orders SET status = @status WHERE (ID = @ID)">
    <DeleteParameters>
        <asp:Parameter Name="ID" />
    </DeleteParameters>
    <UpdateParameters>
        <asp:Parameter Name="status" />
        <asp:Parameter Name="ID" />
    </UpdateParameters>
</asp:SqlDataSource><asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
        DataSourceID="orderadminSqlDataSource" DataKeyNames="ID" Width="608px" 
        AllowPaging="True" AllowSorting="True" PageSize="15">
        <Columns>
            <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
            <asp:BoundField DataField="ID" HeaderText="ID" 
                SortExpression="ID" InsertVisible="False" ReadOnly="True" >
            <ItemStyle HorizontalAlign="Right" />
            </asp:BoundField>
            <asp:BoundField DataField="UserName" HeaderText="Felhasználónév" 
                SortExpression="UserName" >
            <HeaderStyle HorizontalAlign="Center" />
            <ItemStyle HorizontalAlign="Center" />
            </asp:BoundField>
            <asp:BoundField DataField="Quantity" HeaderText="Mennyiség (kg)" 
                SortExpression="Quantity" >
            <HeaderStyle HorizontalAlign="Center" />
            <ItemStyle HorizontalAlign="Center" />
            </asp:BoundField>
            <asp:BoundField DataField="Product" HeaderText="Termék" 
                SortExpression="Product" >
            <HeaderStyle HorizontalAlign="Center" />
            <ItemStyle HorizontalAlign="Center" />
            </asp:BoundField>
            <asp:TemplateField HeaderText="Rendelés státusz" SortExpression="status">
                <EditItemTemplate>
                    <!--<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Status") %>'></asp:TextBox>-->

                    <asp:DropDownList ID="DropDownList1" runat="server" 
                        DataSourceID="statustypeDDLSqlDataSource" DataTextField="name"
                        DataValueField="ID">
                    </asp:DropDownList>
                    <asp:SqlDataSource ID="statustypeDDLSqlDataSource" runat="server" 
                        ConnectionString="<%$ ConnectionStrings:dotnetConnectionString %>" 
                        SelectCommand="SELECT [ID], [name] FROM [status]">
                    </asp:SqlDataSource>

                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="status" runat="server" Text='<%# Bind("Status") %>'></asp:Label>
                </ItemTemplate>
                <HeaderStyle HorizontalAlign="Center" />
                <ItemStyle HorizontalAlign="Center" />
            </asp:TemplateField>
            <asp:BoundField DataField="Date" HeaderText="Dátum" SortExpression="Date" />
        </Columns>
        <PagerSettings PageButtonCount="15" Mode="NumericFirstLast" />
    </asp:GridView>

And here is the orderadminSqlDataSource’s code (the gridview’s datasource)

<!-- language: c# -->
    <asp:SqlDataSource ID="orderadminSqlDataSource" runat="server" 
        ConnectionString="<%$ ConnectionStrings:dotnetConnectionString %>" 
        SelectCommand="SELECT orders.ID, aspnet_Users.UserName, orders.quantity AS Quantity, product.name AS Product, status.name AS Status, orders.date AS Date FROM orders INNER JOIN product ON orders.ordertype = product.ID INNER JOIN status ON orders.status = status.ID INNER JOIN aspnet_Users ON orders.userid = aspnet_Users.UserId ORDER BY date" 
        DeleteCommand="DELETE FROM orders WHERE (ID = @ID)" 
        UpdateCommand="UPDATE orders SET status = @status WHERE (ID = @ID)">
        <DeleteParameters>
            <asp:Parameter Name="ID" />
        </DeleteParameters>
        <UpdateParameters>
            <asp:Parameter Name="status" />
            <asp:Parameter Name="ID" />
        </UpdateParameters>
    </asp:SqlDataSource>

Please help me, i can’t figure out the problem.
Thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T09:12:55+00:00Added an answer on June 7, 2026 at 9:12 am

    I think you’re forgetting to set the DropDown’s SelectedValue property:

    <asp:DropDownList ID="DropDownList1"
                      runat="server" 
                      DataSourceID="statustypeDDLSqlDataSource"
                      DataTextField="name"
                      DataValueField="status"
                      SelectedValue='<%# Bind("status") %>'
                      AppendDataBoundItems="True" >
    

    Change your code for statustypeDDLSqlDataSource:

    <asp:SqlDataSource ID="statustypeDDLSqlDataSource" runat="server" 
                       ConnectionString="<%$ ConnectionStrings:dotnetConnectionString %>" 
                       SelectCommand="SELECT [ID] as status, [name] FROM [status]">
    </asp:SqlDataSource>
    

    You can also simplify this ( no parenthesis necessary ):

    UPDATE orders SET [status] = @status WHERE [ID] = @ID
    

    Note: I had to rename the ID column in the query so that it conforms with the status parameter you defined here:

    <UpdateParameters>
        <asp:Parameter Name="status" />
        <asp:Parameter Name="ID" />
    </UpdateParameters>
    

    My last edit and attempt here 😀

    After carefully looking at your GridView’s SELECT statement I see where the error lies:

    SELECT orders.ID,
           aspnet_Users.UserName,
           orders.quantity AS Quantity,
           product.name AS Product,
           status.name AS Status,
           orders.date AS Date
    FROM orders
    INNER JOIN product ON
    orders.ordertype = product.ID
    INNER JOIN status ON orders.status = status.ID
    INNER JOIN aspnet_Users ON orders.userid = aspnet_Users.UserId
    ORDER BY date
    

    Change it to:

    SELECT orders.ID,
           aspnet_Users.UserName,
           orders.quantity AS Quantity,
           product.name AS Product,
           status.ID AS status,
           status.name AS StatusName,
           orders.date AS Date
    FROM orders
    INNER JOIN product ON
    orders.ordertype = product.ID
    INNER JOIN status ON orders.status = status.ID
    INNER JOIN aspnet_Users ON orders.userid = aspnet_Users.UserId
    ORDER BY date
    

    Now you must change this part too:

    <ItemTemplate>
    <asp:Label ID="status" runat="server" Text='<%# Bind("StatusName") %>'></asp:Label>
    </ItemTemplate>
    

    By the way… here’s a nice step by step tutorial on this matter:

    Walkthrough: Displaying a Drop-Down List While Editing in the GridView Web Server Control

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have this template field inside a gridview. <asp:TemplateField ItemStyle-HorizontalAlign=Center> <ItemTemplate> <asp:ImageButton ID=ImageButton2 ImageUrl=~/images/DeleteRecord.gif
i have a dropdownlist in a gridview <asp:TemplateField HeaderText=Backup Frequency> <ItemTemplate> <asp:DropDownList ID=DropDownList1 runat=server>
I have a DropDownList in a GridView EditItemTemplate. The ddl is to be populated
hi I have this gridview like this. <asp:DropDownList ID=triggerDropDown runat=server AutoPostBack=true onselectedindexchanged=triggerDropDown_SelectedIndexChanged> <asp:GridView ID=myGridView
I have a gridview which is like <asp:TemplateField HeaderText=File Name SortExpression=FileName> <ItemTemplate> <asp:LinkButton ID=lnkname
I have a DropDownList as a TemplateField in a DetailsView. I want to populate
I have a Gridview with a template for this Hyperlink: <asp:TemplateField HeaderText=Notes ItemStyle-CssClass=NoMargin NoPadding
I have a GridView: <asp:GridView ID=gvDownloads> <Columns> <asp:TemplateField HeaderText=Status > <ItemTemplate> <%# Eval(Enabled)%> </ItemTemplate>
I have a GridView like this( main.xml ): <?xml version=1.0 encoding=utf-8?> <GridView xmlns:android=http://schemas.android.com/apk/res/android android:id=@+id/gridView1
I have a gridview data and this gridview have subgrid too. in the first

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.