Solved

template field with dropdownlist and datasource

Posted on 2011-03-02
7
746 Views
Last Modified: 2012-08-14
I have a gridview with a template field that contains a dropdownlist. I would like to set the datasource for this dropdownlist to be either a comma delimited list or the return of the getFiles()  function (whichever is easier). Can someone please tell me how to do this?

Thanks!
Amy
0
Comment
Question by:AmyL
  • 4
  • 2
7 Comments
 
LVL 13

Accepted Solution

by:
agarwalrahul earned 250 total points
ID: 35023836
0
 

Author Comment

by:AmyL
ID: 35023986
That is almost exactly right...I just need one last piece:

Since the datasource is based on a file listing, the selected value of the dropdownlist may no longer exist (for instance, in the event the file was removed). Right now, when that happens, I get this error:

-----------------------------------------------------
dropdownlist1 has a SelectedValue which is invalid because it does not exist in the list of items
-----------------------------------------------------

Is there a way to keep the dropdownlist bound, but allow it to bypass this error in the event that the file no longer exists?

Thanks!
Amy
0
 
LVL 13

Expert Comment

by:agarwalrahul
ID: 35024044
put in try catch block so when the error occurs then it goes to catch block. May be it solves your problem.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:AmyL
ID: 35024113
It isn't in code, it is in the markup:
SelectedValue='<%# Bind("contentBanner") %>'
0
 
LVL 20

Expert Comment

by:informaniac
ID: 35024571
Yet I think u shd be able to check in RowDatabound evnt of the gridview.
0
 

Author Comment

by:AmyL
ID: 35027257
This is a bigger problem than I thought. I am getting this error even when the file does exist...probably because of the timing in creating the datasource on rowbind.

Since it is one dataset with no parameters, I'm thinking it might be better to create an ObjectDatasource and bind to that. Do you know how to do that?
0
 

Author Closing Comment

by:AmyL
ID: 35065950
Thanks - I'll ask the rest in another question.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

680 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question