.ascx
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="ctlInvestType.ascx.cs" Inherits="Controls_ctlInvestType" %>
<%@ OutputCache Duration="3600" VaryByParam="None"%>
<asp:DropDownList ID="ddlInvestType" runat="server">
    <asp:ListItem>上级资金支持</asp:ListItem>
    <asp:ListItem>银行贷款</asp:ListItem>
    <asp:ListItem>自筹</asp:ListItem>
    <asp:ListItem>其它</asp:ListItem>
</asp:DropDownList>.ascx.cs
public partial class Controls_ctlInvestType : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {    }    public string SelectedValue
    {
        get { return ddlInvestType.SelectedValue; }
        set { ddlInvestType.SelectedValue = value; }
    }
}
我在引用控件的页面中 调用 SelectedValue 提示“未将对象初始化”

解决方案 »

  1.   

    public string SelectedValue 
        { 
            get { return ddlInvestType.SelectedValue; } 
            set { ddlInvestType.SelectedValue = value; } 
        } 
    你没定义DropDownList的value值,用ddlInvestType.text
      

  2.   

        public string SelectedValue 
        { 
            get { EnsureChildControls(); return ddlInvestType.SelectedValue; } 
            set { EnsureChildControls(); ddlInvestType.SelectedValue = value; } 
        } 
      

  3.   


    <asp:DropDownList ID="ddlInvestType" runat="server"> 
        <asp:ListItem Value="">上级资金支持 </asp:ListItem> 
        <asp:ListItem Value="">银行贷款 </asp:ListItem> 
        <asp:ListItem Value="">自筹 </asp:ListItem> 
        <asp:ListItem Value="">其它 </asp:ListItem> 
    </asp:DropDownList> 
    你没定义value值所以不能用SelectedValue
      

  4.   

    这是常规了,应该作为一个基础知识不要忘记它。初始化用户控件实例时,并没有装载任何子控件,它的源代码是:
    public class UserControl
    {
    public UserControl()
    {
    }......
    }
      

  5.   

    1楼,3楼作废,看错了,没定义,SelectedValue默认是Text
      

  6.   

    ListItem的value值,它或者是设置的value,或者是text值,或者是string.empty,它永远有值,用不着去为ListItem显示设置value属性。
      

  7.   


    .ascx 
    <%@ Control Language="C#" AutoEventWireup="true" CodeFile="ctlInvestType.ascx.cs" Inherits="Controls_ctlInvestType" %> 
    <%@ OutputCache Duration="3600" VaryByParam="None"%> 
    <asp:DropDownList ID="ddlInvestType" runat="server"> 
        <asp:ListItem value="上级资金支持" text="上级资金支持">上级资金支持 </asp:ListItem> 
        <asp:ListItem value="银行贷款" text="银行贷款">银行贷款 </asp:ListItem> 
        <asp:ListItem value="自筹" text="自筹">自筹 </asp:ListItem> 
        <asp:ListItem value="其它" text="其它">其它 </asp:ListItem> 
    </asp:DropDownList> .ascx.cs 
    public partial class Controls_ctlInvestType : System.Web.UI.UserControl 

        protected void Page_Load(object sender, EventArgs e) 
        {     }     public string SelectedValue 
        { 
            get { return ddlInvestType.SelectedValue; } 
            set { ddlInvestType.SelectedValue = value; } 
        } 

      

  8.   

    添加value
    参考
    http://www.cnblogs.com/luca623/archive/2008/07/01/1233045.html
      

  9.   

    不行还是出错
    吧<%@ OutputCache Duration="3600" VaryByParam="None"%> 注释掉 就可以了
    应该是 缓存的事吧