A way to bind dropdownlist to results from PhotosetsGetList

Topics: Developer Forum
Aug 29, 2010 at 2:04 PM

I'm having trouble with what I thought would be a pretty straightforward task: I'm trying to bind a DDL with the results of the Flickr.PhotosetsGetList method.  But my DDL is showing no results.  (I have one test photoset created on Flickr for the user ID with which I'm working).  Codebehind:

Dim flickr As New Flickr() 

 

Dim PhotoSetOwner = ConfigurationManager.AppSettings("FlickrUserId")
DimPhotoSetList = flickr.PhotosetsGetList(PhotoSetOwner)
DropDownListPhotoSets.DataSource = PhotoSetList
DropDownListPhotoSets.DataBind()

 

The DDL on the markup page is stock:

<

asp:DropDownList ID="DropDownListPhotoSets" runat="server" >

I have not defined datatextfield or datavaluefield in the DDL control.

Do I need to do something special to make this work?

 
Coordinator
Aug 31, 2010 at 8:04 AM

    protected void Page_Load(object sender, EventArgs e)
    {
        Flickr f = new Flickr("XXXX");

        DropDownList1.DataSource = f.PhotosetsGetList("41888973@N00");
        DropDownList1.DataBind();
    }

The above code placed in the Page_Load event produces a list of items in the drop down list. Although without a DataTextField and DataValueField it simply says "FlickrNet.Photoset" on each line, which is what is returned by ToString() for each photoset object.

So if you aren't seeing this then you are either not calling the above code for some reason, or there is something else wrong somewhere else.

 

Aug 31, 2010 at 2:39 PM

Thanks, Sam.  I got the same results (FlickrNet.Photoset) in the dropdownlist without setting the datatextfield and datavaluefield properties.  But after several unsuccessful attempts to set them programmatically, I gave up and set those two properties on the DDL control in the mark-up page.  It worked instantly; it grabbed the returned values from Flickr.PhotosetsGetList method and I'm good. 
  
Still don't what I'm doing wrong to get this wired up properly in the code, but this is an effective workaround.  Thanks a lot for the help.

Coordinator
Aug 31, 2010 at 2:50 PM

If you saw "FlickrNet.Photoset" in your drop down box then it was working correctly. You can set DataTextField and DataValueField programaticallyas well:

DropDownList1.DataTextField = "Title";
DropDownList1.DataValueField = "PhotosetId";

If you don't do that then the default displayed value is the string value returned by ToString() which defaults to the name of the class.