Using ASP.NET Controls without databinding

后端 未结 2 1484
忘掉有多难
忘掉有多难 2021-01-17 01:23

It appears that I have been using asp.net databinding for so long I have forgotten some of the basics.

I am dynamically creating a table in an ASPX page without dat

相关标签:
2条回答
  • 2021-01-17 01:47

    You can pass the parameters by query string.
    something like this :

    foreach (XXX x in TTTT){ %>
       <tr>
           <td><%=x.val %></td>
               <a href='?Action=Resolve&pkid=<%=X.pkid%>'>
                   <img src='../images/IMG.png' />
               </a>
     <% } %>
    
    0 讨论(0)
  • 2021-01-17 01:59

    I'd suggest a listview control. Something like this:

    <asp:ListView ID="lvImages" runat="server" OnItemDataBound="lvImages_ItemDataBound">
        <LayoutTemplate>
            <table class="tblImages" cellpadding="0" cellspacing="0">
                <tr class="ImageHeaderRow">
                    <td>Imagename</td>
                    <td>Image</td>
                    <td>Location</td>
                </tr>
                <asp:PlaceHolder ID="itemContainer" runat="server"></asp:PlaceHolder>
            </table>
        </LayoutTemplate>
        <ItemTemplate>
            <tr>
                <asp:literal ID="ltrCell1" runat="server" />
                <td><asp:ImageButton ID="imgMyImage" runat="server" /></td>
                <td><asp:Label ID="lblLocation" runat="server" ></asp:Label></td>
            </tr>
        </ItemTemplate>
    </asp:ListView>
    

    Code behind :

    protected void lvImages_ItemDataBound(object sender, ListViewItemEventArgs e) {
                if (e.Item.ItemType == ListViewItemType.DataItem) {
                    ListViewDataItem currentItem = (ListViewDataItem)e.Item;
                    MyImageObject oImg = (MyImageObject)currentItem.DataItem;
    
    
                    Literal ltrCell1 = e.Item.FindControl("ltrCell1") as Literal;
                    ImageButton imgMyImage = e.Item.FindControl("imgMyImage") as ImageButton ;
                    Label lblLocation= e.Item.FindControl("lblLocation") as Label;
                    ltrCell1.text = string.format(@"<td id=""{0}"">{1}</td>", oImg.id, oImg.val);
                   imgMyImage.CommandArgument = oImg.arg;
                   imgMyImage.CommandName = "cmdNAme";
                   imgMyImage.ImageUrl = oImg.URL;
    
    }
    

    BEst of Luck!

    0 讨论(0)
提交回复
热议问题