我有一个与FindControl有关的问题。我在转发器中使用ASPxRoundPanel(带有DXperience组件)。我在ASPxRoundPanel中有一个名为“txtAdet ID”的文本框。我只是无法访问Textbox内部。我得到以下错误。
"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;
答案 0 :(得分:0)
ASPxRoundPanel控件是ASPxWebControl的子类,它实现了INamingContainer接口。这意味着调用任何父控件的FindControl(在你的情况下为RepeaterItem)将无法在ASPxRoundPanel中找到任何内容(解释here)。因此,您至少需要两个步骤才能完成任务:
ASPxRoundPanel1 roundPanel = ((ASPxRoundPanel1)e.Item.FindControl("ASPxRoundPanel1"));
TextBox bulunanTextKontrol = ((TextBox)roundPanel.FindControl("txtAdet"));