<EditItemTemplate>
                                    <asp:DropDownList ID="ddl_BigCategory" runat="server" DataTextField="BigCategoryName_CH" DataValueField="BigCategoryID" DataSource="<%# BindBigCate() %>" AppendDataBoundItems="True" SelectedValue='<%# Bind("bid") %>'>
                                    <asp:ListItem Value="-1">請選擇類別</asp:ListItem>
                                    </asp:DropDownList>
                                </EditItemTemplate>aspx.cs
    public SqlDataReader BindBigCate()
    {
        SqlDataReader dr = null;
        try
        { 
            dr = product.GetBigCategories();
                
        }
        catch(Exception ex)
        {
            WebHelper.AlertAndBack(ex.Message);
        }
             return dr;
    }

解决方案 »

  1.   

    多谢楼上的.我在edit模式下手动添加了两个值到dropdownlist中,第一个为Y,第二个为N.我进入页面,此时默认模式为readonly,我的dropdownlist值从数据库读出为N,现在我要去修改,进入edit模式,怎样让dropdownlist的默认值此时也是N?
      

  2.   

    dropdownlist有个属性SelectedValue,经绑定时设置SelectedValue
      

  3.   

    请问如何经绑定时设置SelectedValue呢?
      

  4.   

    DropDownList: SelectedValue='<%# Bind("字段名称") %>'
      

  5.   

    前提是你的DropDownList要有和数据库中字段匹配的ListItem
    如DB中 是aa,bb,cc
    <asp:DropDownList ID="Drop1" runat="server" SelectedValue='<%# Bind("字段名称") %>'>
                           <asp:ListItem>aa</asp:ListItem>
                           <asp:ListItem>bb</asp:ListItem>
                           <asp:ListItem>cc</asp:ListItem>
    </asp:DropDownList>
      

  6.   

    SelectedValue可以,但如果DropDownList 没有SelectedValue这个值会报错的,在ondatabound后遍历dropdownlist,手动设置selected也可.
      

  7.   

    多谢各位了,其实我也是这样绑的:<asp:DropDownList ID="Drop1" runat="server" SelectedValue='<%# Bind("字段名称") %>'>
                           <asp:ListItem>aa</asp:ListItem>
                           <asp:ListItem>bb</asp:ListItem>
                           <asp:ListItem>cc</asp:ListItem>
    </asp:DropDownList>
    但多了个selected=true 就一直报错.谢谢
      

  8.   

    SelectedValue可以,但如果DropDownList 没有SelectedValue这个值会报错,
    解决方法
    设置DropDownList属性   AppendDataBoundItems="true"
    然后添加一个固定的
    <asp:ListItem Text="Null" Value=""></asp:ListItem>