locked
Edit Item Template (amend to dropdownlist) in Details View [Solved] RRS feed

  • Question

  • User-1746893106 posted

    Hi

    I've set a DetailsView and allow auto generate insert button, and the detailview some field customize to dropdownlist.

    View the details is fine but when insert new record, but when insert new row the customize drop down list not return value to sqldatasource.

    It said the drop down list is NULL value. How can I return value to insert record?

    I haven't set parameter in sqldatasource, cause refer to other detailsview (no drop down list) haven't set pararmeter also during insert record.

    Thanks

    datasource
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:myConnectionString %>" 
            InsertCommand="INSERT INTO Printer(BrandId, PrinterModel, PrinterDesc, DeptId, SerialNum, PrinterTypeId, WriteOff, BWCost, ColorCost) 
            VALUES (@brandid, @printermodel, @printerdesc, @deptid, @serialnum, @printtypeid, @writeoff, @bwcost, @colorcost)">
    
    detailsview drop down list
            <asp:DetailsView ID="dwPrinter" runat="server" Height="30%" Width="50%" 
                AutoGenerateRows="False" BackColor="White" BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" CellPadding="3" 
                DataSourceID="SqlDataSource1" ForeColor="Black" GridLines="Vertical" AutoGenerateInsertButton="True">
                <AlternatingRowStyle BackColor="#CCCCCC" />
                <EditRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
                <Fields>
                    <asp:BoundField DataField="PrinterModel" HeaderText="Printer Model" SortExpression="PrinterModel" ReadOnly="True" />
                    <asp:TemplateField HeaderText="Brand Code">
                        <ItemTemplate>
                            <%#Eval("BrandCode") %>
                        </ItemTemplate>
                        <EditItemTemplate>
                            <asp:DropDownList ID="brandid" DataSourceID="sqlBrand" DataTextField="BrandCode" DataValueField="BrandId"
                                selectedvalue='<%# Bind("BrandCode") %>' runat="server"></asp:DropDownList>
                        </EditItemTemplate>
                    </asp:TemplateField>
                    
                    <asp:TemplateField Headertext="Department Code">
                        <ItemTemplate>
                            <%#Eval("DeptCode") %>
                        </ItemTemplate>
                        <EditItemTemplate>
                            <asp:DropDownList ID="ddlDept" DataSourceID="sqlDept" DataTextField="DeptCode" DataValueField="DeptId"
                                SelectedValue='<%# Bind("DeptCode") %>' runat="server"></asp:DropDownList>
                        </EditItemTemplate>
                    </asp:TemplateField>
                    <asp:BoundField DataField="printerdesc" HeaderText="Printer Desc" SortExpression="printerdesc" />
                    <asp:BoundField DataField="serialnum" HeaderText="Serial Num" SortExpression="serialnum" />
                    <asp:TemplateField>
                        <ItemTemplate>
                            <%#Eval("TypeCode") %>
                        </ItemTemplate>
                        <EditItemTemplate>
                            <asp:DropDownList ID="ddlType" DataSourceID="sqlType" DataTextField="TypeCode" DataValueField="PrinterTypeId"
                                SelectedValue='<%# Bind("TypeCode") %>' runat="server"></asp:DropDownList>
                        </EditItemTemplate>
                    </asp:TemplateField>
                    <asp:CheckBoxField DataField="writeoff" HeaderText="Write Off" SortExpression="writeoff" />
                    <asp:BoundField DataField="bwcost" HeaderText="Bw Cost" SortExpression="bwcost" />
                    <asp:BoundField DataField="colorcost" HeaderText="Color Cost" SortExpression="colorcost" />
                </Fields>
                <FooterStyle BackColor="#CCCCCC" />
                <HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />
                <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
            </asp:DetailsView>

    Monday, November 28, 2016 5:52 AM

All replies

  • User177399542 posted

    Use control id's as sql parameters

    e.g:

    //--- Change like this
    @deptid TO @ddlDept 

    Monday, November 28, 2016 6:54 AM
  • User-1746893106 posted

    Thanks anuj_koundal

    Monday, November 28, 2016 8:53 AM