更新参数不会从boundfield获取值

时间:2012-11-28 09:56:32

标签: c# asp.net

我有一个带有一些文本框和下拉列表的BulkEditGridView。 当我尝试更新BulkEditGridView中的记录时,我失败了,因为Updateparameter“Unit”不包含预期值。我希望它包含boundfield的值,该值具有相同名称的DataField属性。这是对的吗?

实际上“hiddenUnit”boundfield只在那里,因为我不知道如何使用“DropDownUnit”字段的选定值作为参数。有一种简单的方法吗?

正如你所知,我是这方面的新手,所以任何帮助都深表感谢。

SqlDataSource:

            <asp:SqlDataSource ID="SqlMealItems" runat="server" ConnectionString="<%$ ConnectionStrings:Kunskapshjulet %>"  
            SelectCommand="SELECT MealItems.ProductId,[Quantity], [Unit], [ProductName], [ItemId] FROM [MealItems] 
                            INNER JOIN Products ON 
                              Products.ProductID = MealItems.ProductId
                            WHERE ([UserId] = @UserId)" 
            UpdateCommand="UPDATE [MealItems] SET [Quantity] = @Quantity, [Unit] = @Unit WHERE UserId = @UserId" >
            <InsertParameters>
                <asp:Parameter Name="Quantity" Type="Int32" />
                <asp:Parameter Name="Unit" Type="Double" />
                <asp:Parameter Name="ProductId" Type="Int32" />
                <asp:Parameter Name="ItemId" Type="String" />
            </InsertParameters>
            <SelectParameters>
                <asp:SessionParameter Name="UserId" SessionField="userID" Type="String" />
            </SelectParameters>
            <UpdateParameters>
                <asp:SessionParameter Name="UserId" SessionField="userID" Type="String" />
                <asp:Parameter Name="Quantity" Type="Int32" />
                <asp:Parameter Name="Unit"  />
             </UpdateParameters>

BulkEditGridView

           <rwg:BulkEditGridView ID="MealList" runat="server" AutoGenerateColumns="False" ShowFooter="True" GridLines="Vertical" CellPadding="4"
             BackColor="White"  DataKeyNames="ItemId,ProductId" SaveButtonID="SaveButton"
            DataSourceID="SqlMealItems"  OnRowUpdate="MealList_RowUpdating"
            OnRowDataBound="MealList_RowDataBound" CssClass="gridView">
             <AlternatingRowStyle CssClass="MealListItemAlt" BackColor="#a6dbed" />
           <Columns>
                <asp:BoundField DataField="ProductId" HeaderText="Prod #" ReadOnly="True" />
                <asp:BoundField DataField="ProductName" HeaderText="Namn" ReadOnly="True" />
                <asp:BoundField DataField="Quantity" HeaderText="Antal"  />
                <asp:TemplateField HeaderText="Enhet">
                    <ItemTemplate>
                        <asp:DropDownList ID="DropDownUnit" OnSelectedIndexChanged="DropDownUnit_SelectedIndexChanged"
                            AutoPostBack="True" runat="server" DataTextField="Unit"  DataValueField="Unit">
                        </asp:DropDownList>
                    </ItemTemplate>
               </asp:TemplateField>
               <asp:BoundField  HeaderText="á pris" ReadOnly="True"  ControlStyle-Width="60" ControlStyle-CssClass="rightAlign" ControlStyle-BorderWidth="1" ControlStyle-BorderColor="#CCCCCC" >
                       <ControlStyle BorderColor="#CCCCCC" BorderWidth="1px" CssClass="rightAlign" Width="60px"></ControlStyle>
                </asp:BoundField>
                <asp:TemplateField HeaderText="Totalt">
                  <ItemTemplate>
                        <asp:TextBox ID="tbTotalPrice" runat = server ReadOnly="true" Width="60" style="text-align:right" BorderWidth="1" BorderColor="#CCCCCC">
                       </asp:TextBox>               
                    </ItemTemplate>
                </asp:TemplateField>
                  <asp:BoundField DataField="Unit" HeaderText="hiddenUnit"  ReadOnly="True" Visible="True" />
           </Columns>
        </rwg:BulkEditGridView>

0 个答案:

没有答案