嵌套网格控件无法访问?空值?问题

时间:2014-11-21 15:31:09

标签: c# asp.net gridview nullreferenceexception

Asp.Net代码

<asp:GridView ID="gv_current_report" runat="server" CssClass="grid" BorderStyle="Solid" BorderColor="#336699" DataKeyNames="staff_id" AutoGenerateColumns="False" GridLines="None" OnRowDataBound="gv_current_report_RowDataBound">
  <AlternatingRowStyle BackColor="#DCE4F9" />
  <Columns>

    <asp:TemplateField>
      <ItemTemplate>
        <img alt="" style="cursor: pointer" src="images/plus.png" width="30" />
        <asp:Panel ID="detail_grid" runat="server" Style="display: none">
          <asp:GridView ID="gv_detail" runat="server" AutoGenerateColumns="false" CssClass="child-grid">
            <Columns>
              <asp:BoundField ItemStyle-Width="150px" DataField="branch_name" HeaderText="Branch Name" />
              <asp:BoundField ItemStyle-Width="150px" DataField="date_contacted" HeaderText="Contacted Date" />
              <asp:BoundField ItemStyle-Width="150px" DataField="name" HeaderText="Staff Name" />
            </Columns>
          </asp:GridView>
        </asp:Panel>
      </ItemTemplate>
    </asp:TemplateField>

C#代码

protected void gv_current_report_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        Int32 staff_id = Convert.ToInt32(gv_current_report.DataKeys[e.Row.RowIndex].Value);
        db = new ReportsDataContext();
        gv_detail.DataSource = db.tracker_new_report_broker_status_change_current_detail(staff_id);
        gv_detail.DataBind();
    }

}

问题是面板和网格视图在c#中无法访问?如果我在设计器中创建控件,它可以访问但是抛出错误

  

对象引用未设置为对象的实例

在运行时发现网格视图控件 NULL

  

(即)gv_detail = Null

任何人都请说清楚。任何帮助将不胜感激!!!

0 个答案:

没有答案