调用自定义控件提示“未将对象引用设置到对象的实例” 动态添加控件代码: 20
StateBoxabox=newStateBox{StateID=single[1]};abox.ID="StateBox"+DateTime.Now.Milliseco...
StateBox abox = new StateBox { StateID=single[1]};
abox.ID = "StateBox" + DateTime.Now.Millisecond.ToString();
Panel_New_All.Controls.Add(abox);
自定义控件ascx代码:
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="StateBox.ascx.cs" Inherits="StateBox" %>
<%@ Register TagPrefix="UserI" TagName="CommentBox" Src="~/UserI/CommentUI.ascx" %>
<asp:FormView ID="Form_State" runat="server" DataSourceID="ODS_State">
<ItemTemplate>
<img src='Face\<%# Eval("SenderID") %>.jpg' alt="头像" />
<a href="~/admin/Student/Person.aspx?ID=<%# Eval("SenderID") %>"><%# Eval("Sender") %></a>
<asp:Label ID="Cont" runat="server"><%# Eval("Cont")%></asp:Label>
<span><%# Common.ShowTimeSpan(Convert.ToDateTime(Eval("CreatTime")))%></span>
<asp:LinkButton ID="UpAll" runat="server" Text="收起回复" OnClick="UpAll_Clicked" CommandName='Up'></asp:LinkButton>
<asp:LinkButton ID="LBtn_ForWard" runat="server" Text="转发" OnClick="Forward" CommandName='<%# Eval("Sender") %>'></asp:LinkButton>
</ItemTemplate>
</asp:FormView>
<UserI:CommentBox ID="CommentBox" runat="server" CommentCount="0" />
<asp:ObjectDataSource ID="ODS_State" runat="server"
SelectMethod="GetDataByID" TypeName="StateDA">
<SelectParameters>
<asp:Parameter Name="ID" Type="String" />
</SelectParameters>
</asp:ObjectDataSource>
c#code代码:
public partial class StateBox : System.Web.UI.UserControl
{
private string _StateID;
public string StateID
{
get { return _StateID; }
set { _StateID = value; }
}
protected void Page_Load(object sender, EventArgs e)
{
ODS_State.SelectParameters[0].DefaultValue = _StateID;//此次就报错了……
}
。。。。。
} 展开
abox.ID = "StateBox" + DateTime.Now.Millisecond.ToString();
Panel_New_All.Controls.Add(abox);
自定义控件ascx代码:
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="StateBox.ascx.cs" Inherits="StateBox" %>
<%@ Register TagPrefix="UserI" TagName="CommentBox" Src="~/UserI/CommentUI.ascx" %>
<asp:FormView ID="Form_State" runat="server" DataSourceID="ODS_State">
<ItemTemplate>
<img src='Face\<%# Eval("SenderID") %>.jpg' alt="头像" />
<a href="~/admin/Student/Person.aspx?ID=<%# Eval("SenderID") %>"><%# Eval("Sender") %></a>
<asp:Label ID="Cont" runat="server"><%# Eval("Cont")%></asp:Label>
<span><%# Common.ShowTimeSpan(Convert.ToDateTime(Eval("CreatTime")))%></span>
<asp:LinkButton ID="UpAll" runat="server" Text="收起回复" OnClick="UpAll_Clicked" CommandName='Up'></asp:LinkButton>
<asp:LinkButton ID="LBtn_ForWard" runat="server" Text="转发" OnClick="Forward" CommandName='<%# Eval("Sender") %>'></asp:LinkButton>
</ItemTemplate>
</asp:FormView>
<UserI:CommentBox ID="CommentBox" runat="server" CommentCount="0" />
<asp:ObjectDataSource ID="ODS_State" runat="server"
SelectMethod="GetDataByID" TypeName="StateDA">
<SelectParameters>
<asp:Parameter Name="ID" Type="String" />
</SelectParameters>
</asp:ObjectDataSource>
c#code代码:
public partial class StateBox : System.Web.UI.UserControl
{
private string _StateID;
public string StateID
{
get { return _StateID; }
set { _StateID = value; }
}
protected void Page_Load(object sender, EventArgs e)
{
ODS_State.SelectParameters[0].DefaultValue = _StateID;//此次就报错了……
}
。。。。。
} 展开
1个回答
展开全部
lectedIndexChanged(object sender, EventArgs e)
{
if (this.lstvDEPT.SelectedItems.Count > 0)
{
this.IDnew = this.lstvDEPT.SelectedItems[0].Tag.ToString();
}
}
0下标不是this.lstvDEPT.SelectedItems[0].SubItems[0]
而是this.lstvDEPT.SelectedItems[0]
{
if (this.lstvDEPT.SelectedItems.Count > 0)
{
this.IDnew = this.lstvDEPT.SelectedItems[0].Tag.ToString();
}
}
0下标不是this.lstvDEPT.SelectedItems[0].SubItems[0]
而是this.lstvDEPT.SelectedItems[0]
追问
您想说明什么?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询