문제

I am getting null exception when using itemdatabound.when I chech ,what I see is item index zero.can u tell me where my repeater is wrong

my repeater ;

        <asp:Repeater runat="server" ID="rptKonutm" OnItemDataBound="rptKonut_ItemDataBound">
            <ItemTemplate>


      <div class="caption">
      <h4 class="pull-right"><%# DataBinder.Eval(Container.DataItem, "Fiyat") %>$</h4>
       <h4>
       <asp:Label runat="server" ID="lblKonutFiyat"></asp:Label>

        </h4>
        <h4 class="pull-right"><%# DataBinder.Eval(Container.DataItem, "Il")%></h4>
        <h4><asp:Label runat="server" ID="lblMevki"></asp:Label></h4>

          <h4 class="pull-right"><%# DataBinder.Eval(Container.DataItem, "EkBilgi")%></h4>
        <h4><asp:Label runat="server" ID="lblDahaFazlaBilgi"></asp:Label></h4>
        <h4 class="pull-right"><%# DataBinder.Eval(Container.DataItem, "AlanMetreKare")%></h4>
          <h4><asp:Label runat="server" ID="lblAlanMetreKare"></asp:Label></h4>
 </div>
                    <!-- Split button -->
                   </ItemTemplate>
        </asp:Repeater>

and code behind ItemDatabound event

protected void rptKonut_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            System.Web.UI.WebControls.Label lblKonutFiyat = (System.Web.UI.WebControls.Label)e.Item.FindControl("lblKonutFiyat");
            System.Web.UI.WebControls.Label lblMevki = (System.Web.UI.WebControls.Label)e.Item.FindControl("lblMevki");
            System.Web.UI.WebControls.Label lblDahaFazlaBilgi = (System.Web.UI.WebControls.Label)e.Item.FindControl("lblDahaFazlaBilgi");
            System.Web.UI.WebControls.Label lblAlanMetreKare = (System.Web.UI.WebControls.Label)e.Item.FindControl("lblAlanMetreKare");


            lblKonutFiyat.Text = MyResource.lblKonutFiyat;
            lblMevki.Text = MyResource.lblMevki;
            lblDahaFazlaBilgi.Text = MyResource.lblDahaFazlaBilgi;
            lblAlanMetreKare.Text = MyResource.lblAlanMetreKare;


        }
도움이 되었습니까?

해결책

Imad is correct you need to check that you are searching in Item rows.

You could find your controls in the following manner to determine the cause of the error:

        Label lblKonutFiyat = e.Item.FindControl("lblKonutFiyat") as Label;

        if (lblKonutFiyat != null)
        {
            lblKonutFiyat.Text = MyResource.lblKonutFiyat;
        }

       ....

If your control is null it will gracefully handle it, any labels that aren't getting set will provide you with the problematic labels.

다른 팁

Try keeping your code in following if

 if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem){}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top