Control in User Control not instantiating

Discussion in 'ASP .Net Building Controls' started by John Teague, Mar 18, 2005.

  1. John Teague

    John Teague Guest

    am building a user control that has a repeater in it. I first started with a
    regular web page to get the formatting right where everything worked
    properly. I then copied it into a new ascx file.

    The repeater is created on the page (not dynamic). I have a function that
    databinds the repeater:

    private void BindRepeater(){
    DataSet ds = new DataSet();
    .. . . create dataset structure . . .;

    repeater.datasource = ds; //error occurs here
    repeater.Databind();
    }

    I get an error message that object reference not set to an instance. When I
    step through with the debugger, the repeater is not instantiated.

    This only happened after I moved it to an ascx page and put the control on
    an aspx page. I have tried calling this function in the page_load, init, and
    prerender.

    Any suggestions?
     
    John Teague, Mar 18, 2005
    #1
    1. Advertising

  2. John Teague

    Brock Allen Guest

    Well, since we don't have your ASCX file I can only make a guess at the problem
    -- Did you add runat=server to your Repeater? Does it have an id="repeater"
    (the variable name you referenced below)?

    -Brock
    DevelopMentor
    http://staff.develop.com/ballen



    > am building a user control that has a repeater in it. I first started
    > with a regular web page to get the formatting right where everything
    > worked properly. I then copied it into a new ascx file.
    >
    > The repeater is created on the page (not dynamic). I have a function
    > that databinds the repeater:
    >
    > private void BindRepeater(){ DataSet ds = new DataSet(); . . . create
    > dataset structure . . .;
    >
    > repeater.datasource = ds; //error occurs here repeater.Databind(); }
    >
    > I get an error message that object reference not set to an instance.
    > When I step through with the debugger, the repeater is not
    > instantiated.
    >
    > This only happened after I moved it to an ascx page and put the
    > control on an aspx page. I have tried calling this function in the
    > page_load, init, and prerender.
    >
    > Any suggestions?
    >
     
    Brock Allen, Mar 18, 2005
    #2
    1. Advertising

  3. John Teague

    John Teague Guest

    The answer is yes to both of your questions. My code has been review by
    other developers and nothing was glarringly wrong with the code (at least to
    us :).

    Here is the repeater tag:
    <asp:repeater id=rptCommissionTable runat="server"
    OnItemDataBound="rptCommissionTable_ItemDataBound">
    <HeaderTemplate>
    <table border="1" cellpadding="0" cellpadding="0">
    <tr>
    <td colspan="12">Universal Life</td>
    </tr>
    <tr>
    <td rowspan="3">
    Carrier
    </td>
    <td rowspan="3">Product Compensation Schedule</td>
    <td colspan="10">Total Commissions as a Function of Penetration
    Percentage</td>
    </tr>
    <tr>
    <td colspan="5">Advisor A</td>
    <td colspan="5">Advisor B</td>
    </tr>
    <tr>
    <td>30%</td>
    <td>40%</td>
    <td>50%</td>
    <td>60%</td>
    <td>70%</td>
    <td>30%</td>
    <td>40%</td>
    <td>50%</td>
    <td>60%</td>
    <td>70%</td>
    </tr>
    </HeaderTemplate>
    <ItemTemplate>
    <tr runat="server">
    <td>
    <asp:Label ID="lblCompensationSchedule" Runat="server"></asp:Label>
    </td>
    <td>
    <asp:Label ID="lblAdvisorARate1" Runat="server"></asp:Label>
    </td>
    <td>
    <asp:Label ID="lblAdvisorARate2" Runat="server"></asp:Label>
    </td>
    <td>
    <asp:Label ID="lblAdvisorARate3" Runat="server"></asp:Label>
    </td>
    <td>
    <asp:Label ID="lblAdvisorARate4" Runat="server"></asp:Label>
    </td>
    <td>
    <asp:Label ID="lblAdvisorARate5" Runat="server"></asp:Label>
    </td>
    <td>
    <asp:Label ID="lblAdvisorBRate1" Runat="server"></asp:Label>
    </td>
    <td>
    <asp:Label ID="lblAdvisorBRate2" Runat="server"></asp:Label>
    </td>
    <td>
    <asp:Label ID="lblAdvisorBRate3" Runat="server"></asp:Label>
    </td>
    <td>
    <asp:Label ID="lblAdvisorBRate4" Runat="server"></asp:Label>
    </td>
    <td>
    <asp:Label ID="lblAdvisorBRate5" Runat="server"></asp:Label>
    </td>
    </tr>
    </ItemTemplate>
    <FooterTemplate>
    </table>
    </FooterTemplate>
    </asp:Repeater>

    and the current codebehind (I have changed this many times to find the
    problem)

    namespace NFP.Benefits.VoluntaryBenefits.Commissions
    {
    /// <summary>
    /// Summary description for VBCommissionMatrix.
    /// </summary>
    public class VBCommissionMatrix : System.Web.UI.UserControl
    {
    protected MetaBuilders.WebControls.GlobalRadioButton rb = new
    GlobalRadioButton();
    protected System.Web.UI.WebControls.Repeater rptCommissionTable;
    protected Label lblTest;
    private int commisionTableRowCount = 1;

    private void Page_Load(object sender, System.EventArgs e)
    {
    // Put user code to initialize the page here



    }
    protected override void OnPreRender(EventArgs e)
    {

    base.OnPreRender (e);
    }

    private void BindCommissionRepeater()
    {
    DataSet ds = new DataSet();
    DataTable dt1 = new DataTable();
    dt1.Columns.Add("Carrier");
    dt1.Columns.Add("CompensationSchedule");
    dt1.Columns.Add("AdvisorARate1");
    dt1.Columns.Add("AdvisorARate2");
    dt1.Columns.Add("AdvisorARate3");
    dt1.Columns.Add("AdvisorARate4");
    dt1.Columns.Add("AdvisorARate5");
    dt1.Columns.Add("AdvisorBRate1");
    dt1.Columns.Add("AdvisorBRate2");
    dt1.Columns.Add("AdvisorBRate3");
    dt1.Columns.Add("AdvisorBRate4");
    dt1.Columns.Add("AdvisorBRate5");

    DataRow row1 = dt1.NewRow();
    row1[0] = "Boston Mutual";
    row1[1] = "First Year 90%";
    row1[2] = "10,530";
    row1[3] = "14,040";
    row1[4] = "17,550";
    row1[5] = "21,060";
    row1[6] = "24,570";
    row1[7] = "7,020";
    row1[8] = "9,360";
    row1[9] = "11,700";
    row1[10] = "14,040";
    row1[11] = "16,380";
    dt1.Rows.Add(row1);

    DataRow row2 = dt1.NewRow();
    row2[0] = "Boston Mutual";
    row2[1] = "Renewal 7%";
    row2[2] = "819";
    row2[3] = "1,092";
    row2[4] = "1,365";
    row2[5] = "1,638";
    row2[6] = "1,911";
    row2[7] = "546";
    row2[8] = "728";
    row2[9] = "910";
    row2[10] = "1,092";
    row2[11] = "1,274";
    dt1.Rows.Add(row2);

    DataRow row3 = dt1.NewRow();
    row3[0] = "Boston Mutual";
    row3[1] = "First Year 90%";
    row3[2] = "10,530";
    row3[3] = "14,040";
    row3[4] = "17,550";
    row3[5] = "21,060";
    row3[6] = "24,570";
    row3[7] = "7,020";
    row3[8] = "9,360";
    row3[9] = "11,700";
    row3[10] = "14,040";
    row3[11] = "16,380";
    dt1.Rows.Add(row3);

    DataRow row4 = dt1.NewRow();
    row4[0] = "Boston Mutual";
    row4[1] = "Renewal 7%";
    row4[2] = "819";
    row4[3] = "1,092";
    row4[4] = "1,365";
    row4[5] = "1,638";
    row4[6] = "1,911";
    row4[7] = "546";
    row4[8] = "728";
    row4[9] = "910";
    row4[10] = "1,092";
    row4[11] = "1,274";
    dt1.Rows.Add(row4);
    ds.Tables.Add(dt1);


    this.rptCommissionTable.DataSource = ds;
    this.rptCommissionTable.DataBind();
    }

    #region Web Form Designer generated code
    override protected void OnInit(EventArgs e)
    {
    //
    // CODEGEN: This call is required by the ASP.NET Web Form Designer.
    //

    InitializeComponent();
    base.OnInit(e);

    }

    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
    {
    this.Load += new System.EventHandler(this.Page_Load);

    }
    #endregion

    protected void rptCommissionTable_ItemDataBound(object sender,
    System.Web.UI.WebControls.RepeaterItemEventArgs e)
    {
    DataRowView data = (DataRowView)e.Item.DataItem;
    if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
    ListItemType.AlternatingItem)
    {
    if(this.commisionTableRowCount % 2 == 0)
    {
    //e.Item.Controls.RemoveAt(2);
    }
    else
    {
    HtmlTableCell carrierCell = new HtmlTableCell();

    GlobalRadioButton grb = new GlobalRadioButton();
    grb.Text = data["Carrier"].ToString();
    grb.GroupName = this.ID + "_radiogroup";

    carrierCell.RowSpan = 2;
    carrierCell.Controls.Add(grb);
    //carrierCell.InnerText = data["Carrier"].ToString();
    ((HtmlTableRow)e.Item.Controls[1]).Cells.Insert(0,carrierCell);

    }
    ((Label)e.Item.FindControl("lblCompensationSchedule")).Text =
    data["CompensationSchedule"].ToString();
    ((Label)e.Item.FindControl("lblAdvisorARate1")).Text =
    data["AdvisorARate1"].ToString();
    ((Label)e.Item.FindControl("lblAdvisorARate2")).Text =
    data["AdvisorARate2"].ToString();
    ((Label)e.Item.FindControl("lblAdvisorARate3")).Text =
    data["AdvisorARate3"].ToString();
    ((Label)e.Item.FindControl("lblAdvisorARate4")).Text =
    data["AdvisorARate4"].ToString();
    ((Label)e.Item.FindControl("lblAdvisorARate5")).Text =
    data["AdvisorARate5"].ToString();
    ((Label)e.Item.FindControl("lblAdvisorBRate1")).Text =
    data["AdvisorBRate1"].ToString();
    ((Label)e.Item.FindControl("lblAdvisorBRate2")).Text =
    data["AdvisorBRate2"].ToString();
    ((Label)e.Item.FindControl("lblAdvisorBRate3")).Text =
    data["AdvisorBRate3"].ToString();
    ((Label)e.Item.FindControl("lblAdvisorBRate4")).Text =
    data["AdvisorBRate4"].ToString();
    ((Label)e.Item.FindControl("lblAdvisorBRate5")).Text =
    data["AdvisorBRate5"].ToString();
    this.commisionTableRowCount++;
    }
    }

    }
    }


    Thanks for the help
     
    John Teague, Mar 18, 2005
    #3
  4. John Teague

    Brock Allen Guest

    Well, I copied this code into a ASPX and did two things:

    1) Called BindCommissionRepeater() from Page_Load
    2) Commented out the references to GlobalRadioButton

    And it worked fine. I'm not sure what the real problem is then :(

    -Brock
    DevelopMentor
    http://staff.develop.com/ballen



    > The answer is yes to both of your questions. My code has been review
    > by other developers and nothing was glarringly wrong with the code (at
    > least to us :).
    >
    > Here is the repeater tag:
    > <asp:repeater id=rptCommissionTable runat="server"
    > OnItemDataBound="rptCommissionTable_ItemDataBound">
    > <HeaderTemplate>
    > <table border="1" cellpadding="0" cellpadding="0">
    > <tr>
    > <td colspan="12">Universal Life</td>
    > </tr>
    > <tr>
    > <td rowspan="3">
    > Carrier
    > </td>
    > <td rowspan="3">Product Compensation Schedule</td>
    > <td colspan="10">Total Commissions as a Function of
    > Penetration
    > Percentage</td>
    > </tr>
    > <tr>
    > <td colspan="5">Advisor A</td>
    > <td colspan="5">Advisor B</td>
    > </tr>
    > <tr>
    > <td>30%</td>
    > <td>40%</td>
    > <td>50%</td>
    > <td>60%</td>
    > <td>70%</td>
    > <td>30%</td>
    > <td>40%</td>
    > <td>50%</td>
    > <td>60%</td>
    > <td>70%</td>
    > </tr>
    > </HeaderTemplate>
    > <ItemTemplate>
    > <tr runat="server">
    > <td>
    > <asp:Label ID="lblCompensationSchedule"
    > Runat="server"></asp:Label>
    > </td>
    > <td>
    > <asp:Label ID="lblAdvisorARate1" Runat="server"></asp:Label>
    > </td>
    > <td>
    > <asp:Label ID="lblAdvisorARate2" Runat="server"></asp:Label>
    > </td>
    > <td>
    > <asp:Label ID="lblAdvisorARate3" Runat="server"></asp:Label>
    > </td>
    > <td>
    > <asp:Label ID="lblAdvisorARate4" Runat="server"></asp:Label>
    > </td>
    > <td>
    > <asp:Label ID="lblAdvisorARate5" Runat="server"></asp:Label>
    > </td>
    > <td>
    > <asp:Label ID="lblAdvisorBRate1" Runat="server"></asp:Label>
    > </td>
    > <td>
    > <asp:Label ID="lblAdvisorBRate2" Runat="server"></asp:Label>
    > </td>
    > <td>
    > <asp:Label ID="lblAdvisorBRate3" Runat="server"></asp:Label>
    > </td>
    > <td>
    > <asp:Label ID="lblAdvisorBRate4" Runat="server"></asp:Label>
    > </td>
    > <td>
    > <asp:Label ID="lblAdvisorBRate5" Runat="server"></asp:Label>
    > </td>
    > </tr>
    > </ItemTemplate>
    > <FooterTemplate>
    > </table>
    > </FooterTemplate>
    > </asp:Repeater>
    > and the current codebehind (I have changed this many times to find the
    > problem)
    >
    > namespace NFP.Benefits.VoluntaryBenefits.Commissions
    > {
    > /// <summary>
    > /// Summary description for VBCommissionMatrix.
    > /// </summary>
    > public class VBCommissionMatrix : System.Web.UI.UserControl
    > {
    > protected MetaBuilders.WebControls.GlobalRadioButton rb = new
    > GlobalRadioButton();
    > protected System.Web.UI.WebControls.Repeater rptCommissionTable;
    > protected Label lblTest;
    > private int commisionTableRowCount = 1;
    > private void Page_Load(object sender, System.EventArgs e)
    > {
    > // Put user code to initialize the page here
    > }
    > protected override void OnPreRender(EventArgs e)
    > {
    > base.OnPreRender (e);
    > }
    > private void BindCommissionRepeater()
    > {
    > DataSet ds = new DataSet();
    > DataTable dt1 = new DataTable();
    > dt1.Columns.Add("Carrier");
    > dt1.Columns.Add("CompensationSchedule");
    > dt1.Columns.Add("AdvisorARate1");
    > dt1.Columns.Add("AdvisorARate2");
    > dt1.Columns.Add("AdvisorARate3");
    > dt1.Columns.Add("AdvisorARate4");
    > dt1.Columns.Add("AdvisorARate5");
    > dt1.Columns.Add("AdvisorBRate1");
    > dt1.Columns.Add("AdvisorBRate2");
    > dt1.Columns.Add("AdvisorBRate3");
    > dt1.Columns.Add("AdvisorBRate4");
    > dt1.Columns.Add("AdvisorBRate5");
    > DataRow row1 = dt1.NewRow();
    > row1[0] = "Boston Mutual";
    > row1[1] = "First Year 90%";
    > row1[2] = "10,530";
    > row1[3] = "14,040";
    > row1[4] = "17,550";
    > row1[5] = "21,060";
    > row1[6] = "24,570";
    > row1[7] = "7,020";
    > row1[8] = "9,360";
    > row1[9] = "11,700";
    > row1[10] = "14,040";
    > row1[11] = "16,380";
    > dt1.Rows.Add(row1);
    > DataRow row2 = dt1.NewRow();
    > row2[0] = "Boston Mutual";
    > row2[1] = "Renewal 7%";
    > row2[2] = "819";
    > row2[3] = "1,092";
    > row2[4] = "1,365";
    > row2[5] = "1,638";
    > row2[6] = "1,911";
    > row2[7] = "546";
    > row2[8] = "728";
    > row2[9] = "910";
    > row2[10] = "1,092";
    > row2[11] = "1,274";
    > dt1.Rows.Add(row2);
    > DataRow row3 = dt1.NewRow();
    > row3[0] = "Boston Mutual";
    > row3[1] = "First Year 90%";
    > row3[2] = "10,530";
    > row3[3] = "14,040";
    > row3[4] = "17,550";
    > row3[5] = "21,060";
    > row3[6] = "24,570";
    > row3[7] = "7,020";
    > row3[8] = "9,360";
    > row3[9] = "11,700";
    > row3[10] = "14,040";
    > row3[11] = "16,380";
    > dt1.Rows.Add(row3);
    > DataRow row4 = dt1.NewRow();
    > row4[0] = "Boston Mutual";
    > row4[1] = "Renewal 7%";
    > row4[2] = "819";
    > row4[3] = "1,092";
    > row4[4] = "1,365";
    > row4[5] = "1,638";
    > row4[6] = "1,911";
    > row4[7] = "546";
    > row4[8] = "728";
    > row4[9] = "910";
    > row4[10] = "1,092";
    > row4[11] = "1,274";
    > dt1.Rows.Add(row4);
    > ds.Tables.Add(dt1);
    > this.rptCommissionTable.DataSource = ds;
    > this.rptCommissionTable.DataBind();
    > }
    > #region Web Form Designer generated code
    > override protected void OnInit(EventArgs e)
    > {
    > //
    > // CODEGEN: This call is required by the ASP.NET Web Form
    > Designer.
    > //
    > InitializeComponent();
    > base.OnInit(e);
    > }
    >
    > /// <summary>
    > /// Required method for Designer support - do not modify
    > /// the contents of this method with the code editor.
    > /// </summary>
    > private void InitializeComponent()
    > {
    > this.Load += new System.EventHandler(this.Page_Load);
    > }
    > #endregion
    > protected void rptCommissionTable_ItemDataBound(object sender,
    > System.Web.UI.WebControls.RepeaterItemEventArgs e)
    > {
    > DataRowView data = (DataRowView)e.Item.DataItem;
    > if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
    > ListItemType.AlternatingItem)
    > {
    > if(this.commisionTableRowCount % 2 == 0)
    > {
    > //e.Item.Controls.RemoveAt(2);
    > }
    > else
    > {
    > HtmlTableCell carrierCell = new HtmlTableCell();
    > GlobalRadioButton grb = new GlobalRadioButton();
    > grb.Text = data["Carrier"].ToString();
    > grb.GroupName = this.ID + "_radiogroup";
    > carrierCell.RowSpan = 2;
    > carrierCell.Controls.Add(grb);
    > //carrierCell.InnerText = data["Carrier"].ToString();
    >
    > ((HtmlTableRow)e.Item.Controls[1]).Cells.Insert(0,carrierCell);
    > }
    > ((Label)e.Item.FindControl("lblCompensationSchedule")).Text =
    > data["CompensationSchedule"].ToString();
    > ((Label)e.Item.FindControl("lblAdvisorARate1")).Text =
    > data["AdvisorARate1"].ToString();
    > ((Label)e.Item.FindControl("lblAdvisorARate2")).Text =
    > data["AdvisorARate2"].ToString();
    > ((Label)e.Item.FindControl("lblAdvisorARate3")).Text =
    > data["AdvisorARate3"].ToString();
    > ((Label)e.Item.FindControl("lblAdvisorARate4")).Text =
    > data["AdvisorARate4"].ToString();
    > ((Label)e.Item.FindControl("lblAdvisorARate5")).Text =
    > data["AdvisorARate5"].ToString();
    > ((Label)e.Item.FindControl("lblAdvisorBRate1")).Text =
    > data["AdvisorBRate1"].ToString();
    > ((Label)e.Item.FindControl("lblAdvisorBRate2")).Text =
    > data["AdvisorBRate2"].ToString();
    > ((Label)e.Item.FindControl("lblAdvisorBRate3")).Text =
    > data["AdvisorBRate3"].ToString();
    > ((Label)e.Item.FindControl("lblAdvisorBRate4")).Text =
    > data["AdvisorBRate4"].ToString();
    > ((Label)e.Item.FindControl("lblAdvisorBRate5")).Text =
    > data["AdvisorBRate5"].ToString();
    > this.commisionTableRowCount++;
    > }
    > }
    > }
    > }
    > Thanks for the help
    >
     
    Brock Allen, Mar 19, 2005
    #4
  5. John Teague

    John Teague Guest

    Thanks for looking into it.

    I tried commenting those out with no luck. The page works fine when it's
    declared as a aspx page. The issue occurs when I try to use it as an ascx
    page.

    Thanks,
    John

    "Brock Allen" wrote:

    > Well, I copied this code into a ASPX and did two things:
    >
    > 1) Called BindCommissionRepeater() from Page_Load
    > 2) Commented out the references to GlobalRadioButton
    >
    > And it worked fine. I'm not sure what the real problem is then :(
    >
    > -Brock
    > DevelopMentor
    > http://staff.develop.com/ballen
    >
    >
    >
    > > The answer is yes to both of your questions. My code has been review
    > > by other developers and nothing was glarringly wrong with the code (at
    > > least to us :).
    > >
    > > Here is the repeater tag:
    > > <asp:repeater id=rptCommissionTable runat="server"
    > > OnItemDataBound="rptCommissionTable_ItemDataBound">
    > > <HeaderTemplate>
    > > <table border="1" cellpadding="0" cellpadding="0">
    > > <tr>
    > > <td colspan="12">Universal Life</td>
    > > </tr>
    > > <tr>
    > > <td rowspan="3">
    > > Carrier
    > > </td>
    > > <td rowspan="3">Product Compensation Schedule</td>
    > > <td colspan="10">Total Commissions as a Function of
    > > Penetration
    > > Percentage</td>
    > > </tr>
    > > <tr>
    > > <td colspan="5">Advisor A</td>
    > > <td colspan="5">Advisor B</td>
    > > </tr>
    > > <tr>
    > > <td>30%</td>
    > > <td>40%</td>
    > > <td>50%</td>
    > > <td>60%</td>
    > > <td>70%</td>
    > > <td>30%</td>
    > > <td>40%</td>
    > > <td>50%</td>
    > > <td>60%</td>
    > > <td>70%</td>
    > > </tr>
    > > </HeaderTemplate>
    > > <ItemTemplate>
    > > <tr runat="server">
    > > <td>
    > > <asp:Label ID="lblCompensationSchedule"
    > > Runat="server"></asp:Label>
    > > </td>
    > > <td>
    > > <asp:Label ID="lblAdvisorARate1" Runat="server"></asp:Label>
    > > </td>
    > > <td>
    > > <asp:Label ID="lblAdvisorARate2" Runat="server"></asp:Label>
    > > </td>
    > > <td>
    > > <asp:Label ID="lblAdvisorARate3" Runat="server"></asp:Label>
    > > </td>
    > > <td>
    > > <asp:Label ID="lblAdvisorARate4" Runat="server"></asp:Label>
    > > </td>
    > > <td>
    > > <asp:Label ID="lblAdvisorARate5" Runat="server"></asp:Label>
    > > </td>
    > > <td>
    > > <asp:Label ID="lblAdvisorBRate1" Runat="server"></asp:Label>
    > > </td>
    > > <td>
    > > <asp:Label ID="lblAdvisorBRate2" Runat="server"></asp:Label>
    > > </td>
    > > <td>
    > > <asp:Label ID="lblAdvisorBRate3" Runat="server"></asp:Label>
    > > </td>
    > > <td>
    > > <asp:Label ID="lblAdvisorBRate4" Runat="server"></asp:Label>
    > > </td>
    > > <td>
    > > <asp:Label ID="lblAdvisorBRate5" Runat="server"></asp:Label>
    > > </td>
    > > </tr>
    > > </ItemTemplate>
    > > <FooterTemplate>
    > > </table>
    > > </FooterTemplate>
    > > </asp:Repeater>
    > > and the current codebehind (I have changed this many times to find the
    > > problem)
    > >
    > > namespace NFP.Benefits.VoluntaryBenefits.Commissions
    > > {
    > > /// <summary>
    > > /// Summary description for VBCommissionMatrix.
    > > /// </summary>
    > > public class VBCommissionMatrix : System.Web.UI.UserControl
    > > {
    > > protected MetaBuilders.WebControls.GlobalRadioButton rb = new
    > > GlobalRadioButton();
    > > protected System.Web.UI.WebControls.Repeater rptCommissionTable;
    > > protected Label lblTest;
    > > private int commisionTableRowCount = 1;
    > > private void Page_Load(object sender, System.EventArgs e)
    > > {
    > > // Put user code to initialize the page here
    > > }
    > > protected override void OnPreRender(EventArgs e)
    > > {
    > > base.OnPreRender (e);
    > > }
    > > private void BindCommissionRepeater()
    > > {
    > > DataSet ds = new DataSet();
    > > DataTable dt1 = new DataTable();
    > > dt1.Columns.Add("Carrier");
    > > dt1.Columns.Add("CompensationSchedule");
    > > dt1.Columns.Add("AdvisorARate1");
    > > dt1.Columns.Add("AdvisorARate2");
    > > dt1.Columns.Add("AdvisorARate3");
    > > dt1.Columns.Add("AdvisorARate4");
    > > dt1.Columns.Add("AdvisorARate5");
    > > dt1.Columns.Add("AdvisorBRate1");
    > > dt1.Columns.Add("AdvisorBRate2");
    > > dt1.Columns.Add("AdvisorBRate3");
    > > dt1.Columns.Add("AdvisorBRate4");
    > > dt1.Columns.Add("AdvisorBRate5");
    > > DataRow row1 = dt1.NewRow();
    > > row1[0] = "Boston Mutual";
    > > row1[1] = "First Year 90%";
    > > row1[2] = "10,530";
    > > row1[3] = "14,040";
    > > row1[4] = "17,550";
    > > row1[5] = "21,060";
    > > row1[6] = "24,570";
    > > row1[7] = "7,020";
    > > row1[8] = "9,360";
    > > row1[9] = "11,700";
    > > row1[10] = "14,040";
    > > row1[11] = "16,380";
    > > dt1.Rows.Add(row1);
    > > DataRow row2 = dt1.NewRow();
    > > row2[0] = "Boston Mutual";
    > > row2[1] = "Renewal 7%";
    > > row2[2] = "819";
    > > row2[3] = "1,092";
    > > row2[4] = "1,365";
    > > row2[5] = "1,638";
    > > row2[6] = "1,911";
    > > row2[7] = "546";
    > > row2[8] = "728";
    > > row2[9] = "910";
    > > row2[10] = "1,092";
    > > row2[11] = "1,274";
    > > dt1.Rows.Add(row2);
    > > DataRow row3 = dt1.NewRow();
    > > row3[0] = "Boston Mutual";
    > > row3[1] = "First Year 90%";
    > > row3[2] = "10,530";
    > > row3[3] = "14,040";
    > > row3[4] = "17,550";
    > > row3[5] = "21,060";
    > > row3[6] = "24,570";
    > > row3[7] = "7,020";
    > > row3[8] = "9,360";
    > > row3[9] = "11,700";
    > > row3[10] = "14,040";
    > > row3[11] = "16,380";
    > > dt1.Rows.Add(row3);
    > > DataRow row4 = dt1.NewRow();
    > > row4[0] = "Boston Mutual";
    > > row4[1] = "Renewal 7%";
    > > row4[2] = "819";
    > > row4[3] = "1,092";
    > > row4[4] = "1,365";
    > > row4[5] = "1,638";
    > > row4[6] = "1,911";
    > > row4[7] = "546";
    > > row4[8] = "728";
    > > row4[9] = "910";
    > > row4[10] = "1,092";
    > > row4[11] = "1,274";
    > > dt1.Rows.Add(row4);
    > > ds.Tables.Add(dt1);
    > > this.rptCommissionTable.DataSource = ds;
    > > this.rptCommissionTable.DataBind();
    > > }
    > > #region Web Form Designer generated code
    > > override protected void OnInit(EventArgs e)
    > > {
    > > //
    > > // CODEGEN: This call is required by the ASP.NET Web Form
    > > Designer.
    > > //
    > > InitializeComponent();
    > > base.OnInit(e);
    > > }
    > >
    > > /// <summary>
    > > /// Required method for Designer support - do not modify
    > > /// the contents of this method with the code editor.
    > > /// </summary>
    > > private void InitializeComponent()
    > > {
    > > this.Load += new System.EventHandler(this.Page_Load);
    > > }
    > > #endregion
    > > protected void rptCommissionTable_ItemDataBound(object sender,
    > > System.Web.UI.WebControls.RepeaterItemEventArgs e)
    > > {
    > > DataRowView data = (DataRowView)e.Item.DataItem;
    > > if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
    > > ListItemType.AlternatingItem)
    > > {
    > > if(this.commisionTableRowCount % 2 == 0)
    > > {
    > > //e.Item.Controls.RemoveAt(2);
    > > }
    > > else
    > > {
    > > HtmlTableCell carrierCell = new HtmlTableCell();
    > > GlobalRadioButton grb = new GlobalRadioButton();
    > > grb.Text = data["Carrier"].ToString();
    > > grb.GroupName = this.ID + "_radiogroup";
    > > carrierCell.RowSpan = 2;
    > > carrierCell.Controls.Add(grb);
    > > //carrierCell.InnerText = data["Carrier"].ToString();
    > >
    > > ((HtmlTableRow)e.Item.Controls[1]).Cells.Insert(0,carrierCell);
    > > }
    > > ((Label)e.Item.FindControl("lblCompensationSchedule")).Text =
    > > data["CompensationSchedule"].ToString();
    > > ((Label)e.Item.FindControl("lblAdvisorARate1")).Text =
    > > data["AdvisorARate1"].ToString();
    > > ((Label)e.Item.FindControl("lblAdvisorARate2")).Text =
    > > data["AdvisorARate2"].ToString();
    > > ((Label)e.Item.FindControl("lblAdvisorARate3")).Text =
    > > data["AdvisorARate3"].ToString();
    > > ((Label)e.Item.FindControl("lblAdvisorARate4")).Text =
    > > data["AdvisorARate4"].ToString();
    > > ((Label)e.Item.FindControl("lblAdvisorARate5")).Text =
    > > data["AdvisorARate5"].ToString();
    > > ((Label)e.Item.FindControl("lblAdvisorBRate1")).Text =
    > > data["AdvisorBRate1"].ToString();
    > > ((Label)e.Item.FindControl("lblAdvisorBRate2")).Text =
    > > data["AdvisorBRate2"].ToString();
    > > ((Label)e.Item.FindControl("lblAdvisorBRate3")).Text =
    > > data["AdvisorBRate3"].ToString();
    > > ((Label)e.Item.FindControl("lblAdvisorBRate4")).Text =
    > > data["AdvisorBRate4"].ToString();
    > > ((Label)e.Item.FindControl("lblAdvisorBRate5")).Text =
    > > data["AdvisorBRate5"].ToString();
    > > this.commisionTableRowCount++;
    > > }
    > > }
    > > }
    > > }
    > > Thanks for the help
    > >

    >
    >
    >
    >
     
    John Teague, Mar 21, 2005
    #5
  6. John Teague

    John Teague Guest

    Ok, I solved the problem. I wanted to confirm that I have reasonably
    explained why this happened.

    What made it work was changing the Register tag to use the source property.
    Originally, I had

    <%@ Register TagPrefix="nfp2" Namespace="VBComparisonMatrix.WebUserControl"
    Assembly="VBCommissionMatrix" %>

    When I changed it to:

    <%@ Register TagPrefix="uc2" TagName="VBCommissionMatrix"
    Src="VBCommissionMatrix.ascx" %>

    It worked.

    The reason I think the src property is the key is because the JIT handles
    everything that I had created on the ascx page that wasn't instantiated in
    the code behind. The first directive only gave the JIT the dll and didn't
    know there was anything else to do. Once I have it the source page, it found
    the repeater and instantiated it.

    Let me know if you think this is correct.

    Thanks for your help.
    John

    "John Teague" wrote:

    > am building a user control that has a repeater in it. I first started with a
    > regular web page to get the formatting right where everything worked
    > properly. I then copied it into a new ascx file.
    >
    > The repeater is created on the page (not dynamic). I have a function that
    > databinds the repeater:
    >
    > private void BindRepeater(){
    > DataSet ds = new DataSet();
    > . . . create dataset structure . . .;
    >
    > repeater.datasource = ds; //error occurs here
    > repeater.Databind();
    > }
    >
    > I get an error message that object reference not set to an instance. When I
    > step through with the debugger, the repeater is not instantiated.
    >
    > This only happened after I moved it to an ascx page and put the control on
    > an aspx page. I have tried calling this function in the page_load, init, and
    > prerender.
    >
    > Any suggestions?
     
    John Teague, Mar 21, 2005
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Patrick Steele [MVP]
    Replies:
    1
    Views:
    514
    John Timney \(Microsoft MVP\)
    Jul 14, 2003
  2. Mike Fors
    Replies:
    2
    Views:
    351
    Mike Fors
    Aug 27, 2003
  3. Andy Fish

    instantiating a template control

    Andy Fish, Apr 1, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    529
    Andy Fish
    Apr 1, 2005
  4. Ike
    Replies:
    1
    Views:
    426
    Oliver Wong
    Jan 19, 2006
  5. Brad Bailey
    Replies:
    1
    Views:
    231
    Steven D'Aprano
    Apr 7, 2011
Loading...

Share This Page