简体   繁体   English

如何访问asp.net中的选定项目

[英]how to access selected item in the asp.net

1-) if I have lots of text, button, link ext in my page, in php when I use them as an array it is possible to use them with the same name. 1-)如果我在页面中有很多文本,按钮,链接扩展名,则当我将它们用作数组时,可以在php中使用相同的名称。 How can I do the same thing in asp.net? 我如何在asp.net中做同样的事情?

2-) I have so many image buttons in my page, my question is: how can I get the selected immage button's id? 2-)我的页面中有很多图像按钮,我的问题是:如何获得所选的图像按钮的ID? because I pring them in the for loop I could not find any solution. 因为我将它们插入for循环中,所以找不到任何解决方案。

this is my code is below first "for loop" is for RSS second "for loop" is for stars and some divs 这是我的代码,下面是第一个“ for循环”用于RSS,第二个“ for循环”用于星星和一些div

        string baslik = "";
        string icerik = "";
        string imageid = "";
   int j = 0;
 if (divflag == false)
  {


    for (int i = 0; i <= 6; i++)
    {
        j++;

         baslik = "baslik" + i;
         icerik = "icerik" + i;
         imageid = "Img"+i;
        this.icerik.InnerHtml = list[i].Description;
        this.baslik.NavigateUrl = list[i].Link;
        this.baslik.Text = list[i].Title;


   %>

<div class="sag-re">-
            <div class="sag-re-baslik" runat="server"><asp:HyperLink ID=baslik         runat="server">HyperLink</asp:HyperLink></div>
                <!--<div class="sag-re-resim"><img src="images/rss-image.jpg" width="120" height="120"  /></div>-->
            <div class="sag-re-icerik" id = icerik runat="server">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc iaculis blandit mauris, in tincidunt erat scelerisque mollis, ac orci. </div>
            <div class="oy-verme">
                 <!-- <body onload="getDivs()"> -->

           <!--  <input type="image"
            src="images/yildiz.png" 
            ID="ImgButton"                                
                runat="server" OnServerClick="ImgButton_ServerClick" />-->
                <% for (j = i * 5 + 1; j < (i *5)+6; j++)
        {

            imageid = "Img" + j;

                       %>
                        <div class="yildiz"><asp:ImageButton ID=Imageid runat="server" Height="19px" 
                        ImageUrl="~/images/yildiz.png" onclick="ImageButton"+<%j %>+"_Click" Width="20px" 
                        style="position: relative; top: 13px; left:6px; float:left; "   /></div>


       <% } %>


        <div class="oy-sil"><img src="images/oy-sil.png" width="11" height="13" style="position: relative; top: 30px; " /></div>
            </div>
             <div class="bilgi" id="rate"><b>Rate</b> : 2.52  &nbsp;<img     src="images/mail.jpg" width="12" height="8" /><a href="#"> Mail</a> &nbsp; <img src="images/favorites.png" width="9" height="9" /><a href="#"> Add to favorites</a>&nbsp; <img src="images/tags.png" width="9" height="8" /><a href="#"> Add Tags</a> &nbsp; <img src="images/comment.png" width="11" height="8" /><a href="#"> Add Comment</a> &nbsp; <img src="images/show-comment.png" width="9" height="10" /> <a href="#">Show Comments</a><br /> <b>Tags</b> : tag1, tag2, tag3</div>

You might want to look into using a repeater control instead of attempting to do a for loop within the ASP.NET page. 您可能想研究使用中继器控件,而不是尝试在ASP.NET页中进行for循环。 ASP.NET typically works using the event-based model and databinding. ASP.NET通常使用基于事件的模型和数据绑定来工作。 So what you would do is to bind your repeater to your datasource add an event handler to the onItemDataBound event for your repeater and get the controls using the findControl method to set the properties for that specific control. 因此,您要做的就是将中继器绑定到数据源,将事件处理程序添加到中继器的onItemDataBound事件,并使用findControl方法获取控件以设置该特定控件的属性。 Check out this link... 查看此链接...

https://stackoverflow.com/a/1847790/565792 https://stackoverflow.com/a/1847790/565792

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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