你调用的对象是空的。我能从这些错误中得到帮助吗? [英] Object reference not set to an instance of an object. can I get Help form these error

查看:92
本文介绍了你调用的对象是空的。我能从这些错误中得到帮助吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

DropDownList status =(DropDownList)DemoGridView.FooterRow.FindControl(FooterStatus);

..........



...........

catch(execption e)//获取错误:对象引用未设置为对象的实例。

{

}

解决方案

在您的代码中,DemoGridView.FooterRow可能为null,这就是为什么你有这个例外或在页脚没有FooterStatus名称的对象。



  foreach (GridViewRow  DemoGridView.Rows中的行 {
if (row.RowType == DataControlRowType.DataRow) {
DropDownList status = row.FindControl( FooterStatus as DropDownList;
}
}


 <   asp:TemplateField     HeaderText   = 状态 >  

< ItemTemplate >
< asp:Label ID = lblStatus < span class =code-attribute> runat = server

< span class =code-attribute> 文字 =' <% #Bind( 状态)< span class =code-pagedirective>%> ' > < / asp:标签 >
< / ItemTemplate >
< EditItemTemplate >
< asp:DropDownList ID = EditStatus runat = 服务器 >
<% - < asp:ListItem>已婚< / asp:ListItem >
< < span class =code-leadattribute> asp:ListItem > 未婚< < span class =code-leadattribute> / asp:ListItem >
< asp:ListItem > < / asp:ListItem > - %>
< / asp:DropDownList >

< / EditItemTemplate >
< FooterTemplate >
< asp:DropDownList ID = FooterStatus runat = 服务器 >
<% - < asp:ListItem>已婚< / asp:ListItem >
< asp:ListItem > 未婚< / asp:ListItem >
< asp:ListItem > < / asp:ListItem > - %>
< / asp:DropDownList >
< / FooterTemplate >
< / asp:TemplateField >


DropDownList status = (DropDownList)DemoGridView.FooterRow.FindControl("FooterStatus");
..........

...........
catch(execption e)// Getting an error: Object reference not set to an instance of an object.
{
}

解决方案

In your code DemoGridView.FooterRow is probably null that's why you've got that exception or in the footer there is no object with FooterStatus name.

foreach(GridViewRow row in DemoGridView.Rows) {
    if(row.RowType == DataControlRowType.DataRow) {
        DropDownList status = row.FindControl("FooterStatus") as DropDownList;
    }
}


<asp:TemplateField HeaderText="Status">

                      <ItemTemplate>
                          <asp:Label ID="lblStatus" runat="server"

                              Text='<%# Bind("Status") %>'></asp:Label>
                      </ItemTemplate>
                      <EditItemTemplate>
                          <asp:DropDownList ID="EditStatus" runat="server">
                              <%--<asp:ListItem>Married</asp:ListItem>
                  <asp:ListItem>Unmarried</asp:ListItem>
                  <asp:ListItem>None</asp:ListItem>--%>
                          </asp:DropDownList>

                      </EditItemTemplate>
                      <FooterTemplate>
                          <asp:DropDownList ID="FooterStatus" runat="server">
                              <%-- <asp:ListItem>Married</asp:ListItem>
                  <asp:ListItem>Unmarried</asp:ListItem>
                  <asp:ListItem>None</asp:ListItem>--%>
                          </asp:DropDownList>
                      </FooterTemplate>
                  </asp:TemplateField>


这篇关于你调用的对象是空的。我能从这些错误中得到帮助吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆