简体   繁体   中英

I Can't Use/Call the TextBox Inside the Item Template in the aspx.cs

As you can see I have TextBox in the ItemTemplate. What I want to do is: I want to use TxtUrunID in database code in default.aspx.cs but I can not find TxtUrunID. What can I do?

<asp:Repeater ID="Repeater2" runat="server" DataSourceID="SqlDataSource2">
    <ItemTemplate>
        <li class="<%#Eval("urunkategoriadi") %>">
            <figure>
                <div class="gallery-img"><asp:LinkButton ID="LinkButton1" runat="server" OnClick="LinkButton1_Click"><img src="<%#Eval("urunresmi") %>" alt="" /></asp:LinkButton></div>
                <figcaption>
                    <asp:TextBox ID="TxtUrunID" runat="server" CssClass="form-control" Text='<%#Eval("urunid") %>' Visible="false"></asp:TextBox>
                    <h3><%#Eval("urunadi") %></h3>
                    <p>Ürün hakkında detaylı bilgi için tıklayınız.</p>
                </figcaption>
            </figure>
        </li>
    </ItemTemplate>
</asp:Repeater>
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:aytasarimConnectionString %>" SelectCommand="SELECT [urunid], [urunadi], [urunkategoriadi], [urunresmi] FROM [urun]"></asp:SqlDataSource>

default.aspx.cs page and my SQL code (SELECT code) is here:

I guess you can't access the textbox because it's inside the repeater. That means you have more than one textbox. You may be able to access it with code like this:

foreach (RepeaterItem item in Repeater2.Items)
{
  TextBox txtName= (TextBox)item.FindControl("TxtUrunID");
  if(txtName!=null)
  {
    //do something with txtName.Text
  }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM