cs文件里如下:
        if (Request.QueryString["action"] == "modi" && Request.QueryString["id"] != null)
        {
            Mofi_Pl.Visible = true;
            Image1.Visible = false;
            int modiId = int.Parse(Request.QueryString["id"]);   //得到需要显示的记录的编号(Id)
            SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["sqlcon"]);
            con.Open();
            string modisql = "Select site,username From [user] Where Id=" + modiId;  //生成Sql 语句。
            SqlCommand modi = new SqlCommand(modisql, con);
            SqlDataReader dr = modi.ExecuteReader();
            if (dr.Read())
            {
                lb_uid.Text = dr["username"].ToString();
                m_sitename = dr["sitename"].ToString();
                m_site = dr["site"].ToString();
            }
            dr.Close();
            con.Close();
        
        }
aspx文件如下:
<asp:DropDownList ID="m_ddl_site" runat="server" CssClass="select">
<asp:ListItem Value="<%# m_site%>" Selected="True"><%# m_sitename %></asp:ListItem>
</asp:DropDownList>提示错误如下:
分析器错误信息: 仅对具有 DataBinding 事件的对象提供数据绑定表达式支持。System.Web.UI.WebControls.ListItem 没有 DataBinding 事件。
行 152:                                             <asp:ListItem Value="<%# m_site%>" Selected="True"><%# m_sitename %></asp:ListItem>

解决方案 »

  1.   

    把数据写入一个DataTable中,绑定到控件就可以
      

  2.   

    <asp:ListItem Value="<%= m_site%>" Selected="True"><%= m_sitename %></asp:ListItem>
      

  3.   

    <%# 变量名%>可以这样
    DataTable怎么用呢,能不能按这例子帮我写个,谢谢了!!!
      

  4.   

    ListItem不止一项,有好多静态的,不是数据库的,我的意思就要数据库里的读出来做为默认的..
      

  5.   

    <asp:ListItem Value="<%# m_site%>" Selected="True"><%# m_sitename %></asp:ListItem>
    怎么没有id?
      

  6.   

    id在DropDownList里ListItem是没有ID的
      

  7.   

    在.cs中把变量设置为public型就可以了
      

  8.   

    是的,只要把.cs中把变量设置为public型就可以了。
      

  9.   

    这里有好多例子
    http://www.cshap.com.cn