#1
  1. Business Analyst
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Mar 2004
    Location
    The 'Ville
    Posts
    1,087
    Rep Power
    22

    GridView bind C# struct


    Code:
    <asp:GridView runat="server" ID="gvCart" AutoGenerateColumns="false" >
                <Columns>
                    <asp:BoundField Visible="false" DataField='<%# DataBinder.Eval(((code.redbooth.PhotoAttributes)Container.DataItem).PhotoID) %>' />
                    <asp:ImageField DataImageUrlField='<%# Eval(((code.redbooth.PhotoAttributes)Container.DataItem).SmallUrl) %>' />
                </Columns>
            </asp:GridView>
    Code:
    List<code.redbooth.PhotoAttributes> lstPhotoAttributes = null;
    
    Flickr flickr = new Flickr(WebConfigurationManager.AppSettings["flickrKey"], WebConfigurationManager.AppSettings["flickrSecret"]);
                    PhotoInfo pi = flickr.PhotosGetInfo(Request.QueryString["imageID"]);
    
                    code.redbooth.PhotoAttributes photo = new code.redbooth.PhotoAttributes();
                    photo.PhotoID = pi.PhotoId;
                    photo.SmallUrl = pi.SmallUrl;
                    
                    lstPhotoAttributes.Add(photo);
    
                    Response.Write("PHOTO ADDED");
    Code:
    public struct PhotoAttributes
            {
                private string strPhotoID;
                private string strSmallUrl;
                private int nSize4x6Quantity;
                private int nSize5x7Quantity;
                private int nSize8x10Quantity;
    
                public PhotoAttributes(string strNewPhotoID, string strNewSmallUrl)
                {
                    strPhotoID = strNewPhotoID;
                    strSmallUrl = strNewSmallUrl;
                    nSize4x6Quantity = 0;
                    nSize5x7Quantity = 0;
                    nSize8x10Quantity = 0;
                }
    
                public string PhotoID
                {
                    get { return strPhotoID; }
                    set { strPhotoID = value; }
                }
    
                public string SmallUrl
                {
                    get { return strSmallUrl; }
                    set { strSmallUrl = value; }
                }
    
                public int Size4x6Quantity
                {
                    get { return nSize4x6Quantity; }
                    set { nSize4x6Quantity = value; }
                }
    
                public int Size5x7Quantity
                {
                    get { return nSize5x7Quantity; }
                    set { nSize5x7Quantity = value; }
                }
    
                public int Size8x10Quantity
                {
                    get { return nSize8x10Quantity; }
                    set { nSize8x10Quantity = value; }
                }
            }
    Not having any luck here. When this gets bound I get the following message for the first column. " Databinding expressions are only supported on objects that have a DataBinding event. System.Web.UI.WebControls.BoundField does not have a DataBinding event."

    Any suggestions?

    Thanks!
    Discontent is the first necessity of progress. - Edison
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2013
    Posts
    18
    Rep Power
    0
    I am recently also run into .NET development and feel a great headache on the .NET gridview data-binding. I read your code and perceived nothing seriously wrong. However, maybe mistakes happens in some detailed part, but I can't figure out. Gridview is an aweful thing...

IMN logo majestic logo threadwatch logo seochat tools logo