| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 766 人关注过本帖
标题:“DropDownList1”有一个无效 SelectedValue,因为它不在项目列表中
只看楼主 加入收藏
轩齐
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2010-9-22
收藏
 问题点数:0 回复次数:1 
“DropDownList1”有一个无效 SelectedValue,因为它不在项目列表中
DropDownList和其相关数据库SqlDataSource
<asp:DropDownList ID="DropDownList1" runat="server"
                                DataSourceID="SqlDataSource1" DataTextField="Address" DataValueField="Address"
                                SelectedValue='<%# Bind("Address") %>'>

                                <asp:ListItem>江苏</asp:ListItem>

                            </asp:DropDownList>
                            <br />
                            <asp:SqlDataSource ID="SqlDataSource1" runat="server"
                                ConnectionString="<%$ ConnectionStrings:TestConnString %>"
                                SelectCommand="SELECT * FROM [Provice]"></asp:SqlDataSource>
.cs文件代码如下
 protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
       // return;
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            if (e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate)
            {
                //User info = e.Row.DataItem ;
                //e.Row.Cells[2].Text = (info.Sex as string?).Value == "M" ? "男" : "女";
            }
        }
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            DropDownList DropDownList1 = e.Row.FindControl("DropDownList1") as DropDownList;
            if (DropDownList1 != null)
            {
             //   DropDownList1.Items.Clear();
              // DropDownList1.DataSource = SqlDataSource1;
              //  DropDownList1.DataTextField = "Address";
              //  DropDownList1.DataValueField = "Address";
              //  DropDownList1.DataBind();
                DropDownList1.Items.Add("江苏");
              //  DropDownList1.Items.Insert(0, new ListItem("--请选择--", ""));
                DropDownList1.SelectedValue = "江苏";
               
                if (DataBinder.Eval(e.Row.DataItem, "Address") != null)
                {
                    DropDownList1.SelectedValue = DataBinder.Eval(e.Row.DataItem, "Address").ToString();
                }
                else
                {
                    DropDownList1.SelectedIndex = 0;
                    
                    
                    
                }
            }

        }


    }
怎么解决啊????????????????????

[ 本帖最后由 轩齐 于 2011-4-10 15:37 编辑 ]
搜索更多相关主题的帖子: 数据库 江苏 
2011-04-10 15:28
轩齐
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2010-9-22
收藏
得分:0 
怎么没人回呢?郁闷
2011-04-10 15:57
快速回复:“DropDownList1”有一个无效 SelectedValue,因为它不在项目列表中
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017059 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved