查找控件问题

发布于 2024-11-25 18:01:19 字数 3339 浏览 0 评论 0原文

我有一个关于 FindControl 的问题。我在中继器中使用 ASPxRoundPanel(带有 DXperience 组件)。我在 ASPxRoundPanel 中有一个名为“txtAdet ID”的文本框。我只是无法访问文本框内部。并且出现以下错误。

"Object reference not set to an instance of an object." 

ascx。代码:

<asp:Repeater ID="Repeater1" runat="server" DataSourceID="urunLinq"
    onitemcommand="Repeater1_ItemCommand">
<ItemTemplate>

    <dxrp:ASPxRoundPanel ID="ASPxRoundPanel1" runat="server" Width="980px" ShowHeader="true" Height="550px">
   <PanelCollection>
   <dxrp:PanelContent>
   <div style="width:980; overflow:hidden;height:350px;">
   <div style="float:left; width:410px;height:310px;">
    <asp:Image ID="Image1" Width="400" Height="300" ImageUrl='<%# "../urunResim/"+Eval("urunAnaResim") %>' runat="server" />
</div>
<div style="float:left;margin-top:0px;overflow:hidden;width:500px;">
<h2><%# Eval("urunAdi") %></h2>

<h4>Ürün Özellikleri</h4>
<p style="font-size:x-small;"><%# Eval("urunOzellikleri") %></p>
<br />
<table>
<tr>
<td><h5>Adet    </h5></td><td><asp:TextBox ID="txtAdet" Width="50" runat="server"></asp:TextBox></td>
<td><h4>        Peşin Fiyatı :</h4></td><td><h3 style="color:Red;">  <%# Eval("kdvliFiyat") %>TL</h3></td>
</tr>
</table>
<br />
<table>
<tr>
<td><a href="#">İnternet satış taksitlerini görmek için tıklayın.</a></td>
<td>                
<asp:ImageButton ID="ImageButton1" CommandName="sepeteKaydet" runat="server" ImageUrl="~/img/icons/sepeteEkle.JPG" /></td>
</tr>
</table>
</div></div>

   </dxrp:PanelContent>
   </PanelCollection>
   <HeaderTemplate>
   <h3><%# Eval("urunAdi") %></h3>
   </HeaderTemplate>
    </dxrp:ASPxRoundPanel>

</ItemTemplate>
</asp:Repeater> 

.cs 代码:

protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            if (e.CommandName=="sepeteKaydet")
            {
               TextBox bulunanTextKontrol = ((TextBox)e.Item.FindControl("txtAdet"));
               string urunAdet = bulunanTextKontrol.Text;
               string sessionId = Session.SessionID;
               int urunId=Convert.ToInt32(Request["id"].ToString());
               tempSepet geciciSepet = new tempSepet()
               {
                    adet = Convert.ToInt32(urunAdet),
                    eklemeSaati = Convert.ToString(DateTime.Now.Hour.ToString()),
                    eklemeTarihi = Convert.ToString(DateTime.Now.ToShortDateString()),
                    sessionId = sessionId,
                    urunId = urunId
               };
               selcukData.tempSepets.InsertOnSubmit(geciciSepet);
               selcukData.SubmitChanges();
               Response.Write("<script type='text/javascript'>alert('Ürün sepetinize başarıyla eklendi')</script>");
               ((TextBox)e.Item.FindControl("txtAdet")).Text = null;
            }
        } 

我在以下行中收到错误。

 string urunAdet = bulunanTextKontrol.Text;

I have a problem regarding with FindControl.I'm using ASPxRoundPanel(with DXperience component) in a repeater. I have a textbox called "txtAdet ID" in ASPxRoundPanel. I just can't access inside the Textbox.And I got the following the error.

"Object reference not set to an instance of an object." 

ascx. code:

<asp:Repeater ID="Repeater1" runat="server" DataSourceID="urunLinq"
    onitemcommand="Repeater1_ItemCommand">
<ItemTemplate>

    <dxrp:ASPxRoundPanel ID="ASPxRoundPanel1" runat="server" Width="980px" ShowHeader="true" Height="550px">
   <PanelCollection>
   <dxrp:PanelContent>
   <div style="width:980; overflow:hidden;height:350px;">
   <div style="float:left; width:410px;height:310px;">
    <asp:Image ID="Image1" Width="400" Height="300" ImageUrl='<%# "../urunResim/"+Eval("urunAnaResim") %>' runat="server" />
</div>
<div style="float:left;margin-top:0px;overflow:hidden;width:500px;">
<h2><%# Eval("urunAdi") %></h2>

<h4>Ürün Özellikleri</h4>
<p style="font-size:x-small;"><%# Eval("urunOzellikleri") %></p>
<br />
<table>
<tr>
<td><h5>Adet    </h5></td><td><asp:TextBox ID="txtAdet" Width="50" runat="server"></asp:TextBox></td>
<td><h4>        Peşin Fiyatı :</h4></td><td><h3 style="color:Red;">  <%# Eval("kdvliFiyat") %>TL</h3></td>
</tr>
</table>
<br />
<table>
<tr>
<td><a href="#">İnternet satış taksitlerini görmek için tıklayın.</a></td>
<td>                
<asp:ImageButton ID="ImageButton1" CommandName="sepeteKaydet" runat="server" ImageUrl="~/img/icons/sepeteEkle.JPG" /></td>
</tr>
</table>
</div></div>

   </dxrp:PanelContent>
   </PanelCollection>
   <HeaderTemplate>
   <h3><%# Eval("urunAdi") %></h3>
   </HeaderTemplate>
    </dxrp:ASPxRoundPanel>

</ItemTemplate>
</asp:Repeater> 

.cs code:

protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            if (e.CommandName=="sepeteKaydet")
            {
               TextBox bulunanTextKontrol = ((TextBox)e.Item.FindControl("txtAdet"));
               string urunAdet = bulunanTextKontrol.Text;
               string sessionId = Session.SessionID;
               int urunId=Convert.ToInt32(Request["id"].ToString());
               tempSepet geciciSepet = new tempSepet()
               {
                    adet = Convert.ToInt32(urunAdet),
                    eklemeSaati = Convert.ToString(DateTime.Now.Hour.ToString()),
                    eklemeTarihi = Convert.ToString(DateTime.Now.ToShortDateString()),
                    sessionId = sessionId,
                    urunId = urunId
               };
               selcukData.tempSepets.InsertOnSubmit(geciciSepet);
               selcukData.SubmitChanges();
               Response.Write("<script type='text/javascript'>alert('Ürün sepetinize başarıyla eklendi')</script>");
               ((TextBox)e.Item.FindControl("txtAdet")).Text = null;
            }
        } 

I got a error the following line.

 string urunAdet = bulunanTextKontrol.Text;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

╰つ倒转 2024-12-02 18:01:19

ASPxRoundPanel 控件是 ASPxWebControl 的子类,它实现 INamingContainer 接口。这意味着调用任何父控件(在您的情况下为 RepeaterItem)的 FindControl 将无法在 ASPxRoundPanel 中找到任何内容(解释 此处)。因此,您至少需要两个步骤来完成任务:

ASPxRoundPanel1 roundPanel =  ((ASPxRoundPanel1)e.Item.FindControl("ASPxRoundPanel1"));
TextBox bulunanTextKontrol = ((TextBox)roundPanel.FindControl("txtAdet"));

ASPxRoundPanel control is a subclass of ASPxWebControl which implements INamingContainer interface. It means that FindControl called on any parent control (RepeaterItem at your case) won't be able to find anything inside ASPxRoundPanel (explanation here). So you need at least two steps to accomplish your task:

ASPxRoundPanel1 roundPanel =  ((ASPxRoundPanel1)e.Item.FindControl("ASPxRoundPanel1"));
TextBox bulunanTextKontrol = ((TextBox)roundPanel.FindControl("txtAdet"));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文