日期:2014-05-17  浏览次数:21030 次

listview的编辑模板里边,如何获取dropdownlist下拉列表对应的值,我要添加到SqlDataSource数据源控件中读不出来,求帮助!
        <EditItemTemplate>
              <asp:Button ID="UpdateButton" runat="server" CommandName="Update" Text="更新" />
              <asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="取消" />
              <asp:Label ID="WareIdLabel1" runat="server" Text='<%# Eval("WareId") %>' />
              <asp:TextBox ID="WareNameTextBox" runat="server"Text='<%# Bind("WareName")%>' />
             <asp:TextBox ID="WarePriceTextBox" runat="server" Text='<%# Bind("WarePrice") %>'/>
            <asp:TextBox ID="WareDateTextBox" runat="server" Text='<%# Bind("WareDate") %>' />
             <asp:TextBox ID="PawnDateTextBox" runat="server"Text='<%# Bind("PawnDate") %>' />
    <asp:TextBox ID="WareClassNameTextBox" runat="server" Text='<%# Bind("WareClassName") %>' />
              <asp:TextBox ID="epotHowTextBox" runat="server" Text='<%# Bind("epotHow") %>' />
              <asp:DropDownList ID="DropDownList1" runat="server" DataTextField='WareClassName'  
                 DataValueField='WareClassID' DataSourceID="SqlDataSource1" AutoPostBack="True">
              </asp:DropDownList>
        </EditItemTemplate>
          
我点完更新就提示“不能将值 NULL 插入列 'WareClassId',表 'goshopping.dbo.WareParticularClass';列不允许有 Null 值。UPDATE 失败。
语句已终止。”
我又不能直接绑定WareClassId,因为这个列是个对表连接,他自己也不能获取dropdownlist的value值,如果我把dropdown写成数据绑定的形式,dropdownlist也会报错,请各位大侠,高手帮助!

------解决方案--------------------
插入断点,循环一下看看,应该是dropdownlist的项中有null了,是不是你循环的时候多了一次?
------解决方案--------------------
这样的问题还是自己仔细调试下了。
------解决方案---------------