Using ASP.NET Controls without databinding

后端 未结 2 1483
忘掉有多难
忘掉有多难 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:59

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

    
        
            
    Imagename Image Location

    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(@"{1}", oImg.id, oImg.val);
                   imgMyImage.CommandArgument = oImg.arg;
                   imgMyImage.CommandName = "cmdNAme";
                   imgMyImage.ImageUrl = oImg.URL;
    
    }
    

    BEst of Luck!

提交回复
热议问题