Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8676585
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T20:14:00+00:00 2026-06-12T20:14:00+00:00

I have an ObjectDataSource for my FormView (Students) and another ObjectDatSource for the DropDownList

  • 0

I have an ObjectDataSource for my FormView (Students) and another ObjectDatSource for the DropDownList (Name) within the FormView. If the DropDownList’s source does not contain a name value matching the formview’s source, I would like to display “Not available”. Currently I have this code, which works if the datasource returns a NULL value. How can I change this to display “Not Available” when the FormView name value is not in the DropDownList’s databound list?

<asp:FormView ID="Students" runat="server" DataSourceID="Students_DataSource">
    <ItemTemplate>
        <asp:Label ID="lblName" runat="server" Text='<%# Eval("Name") %>' />
    </ItemTemplate>
    <EditTemplate>
        <asp:DropDownList ID="ddlName" runat="server" 
        SelectedValue='<%# If(Eval("Name") IsNot Nothing, Eval("Name"), "Not Available") %>' 
                    DataSourceID="fvAllNames" runat="server" DataTextField="Name" DataValueField="Name" />        
    </EditTemplate>
</asp:FormView>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T20:14:02+00:00Added an answer on June 12, 2026 at 8:14 pm
    public class MyItem
    {
        public string Name { get; set; }
        public int UserId { get; set; }
    }
    
    public void MethodThatLoadsMyData
    {
        var originalListData = MethodThatFetchesMyData(45);
        myDropDownList.DataSource = MethodThatBumpsTwoItemDatasources(myOuterList, originalListData);
        myDropDownList.DataBind();
    }
    
    public void MethodThatBumpsTwoItemDatasources(List<MyItem> outerList, List<MyItem> dropdownList)
    {
        /*This modifies the original result set from the database that you were going
        to use to populate your dropdown list. It compares the outer list (whatever that is)
        with the result set, and adds items called "Not Available" when there is an item in the
        outer list that doesn't exist in the dropdownlist */
    
        var result = new List<Item>();
        foreach (var item in listA)
        {
            var matched = false;
            foreach (var itemB in listB.Where(itemB => itemB.Id == item.Id))
            {
                matched = true;
                result.Add(item);
            }
            if (!matched)
            {
                result.Add(new Item
                {
                    Name = "Not Available",
                    Id = 0
                });
            }
            matched = false; 
        }
        return result;
    }
    
    public List<MyItem> MethodThatFetchesMyData(int myParameter)
    {
        //gets my data from the database and builds dto objects
        var sql = "my_stored_procedure_or_sql";
        var list = new List<MyItems>();
        using(var conn = new SqlConnection(myConnectionString))
        {
            using(var comm = new SqlCommand(sql, conn))
            {
                //do your normal client setup here (sql type, parameters, etc//
                var parameters = SqlParameter[1];
                parameters[0] = new SqlParameter("@ParameterName", DbType.Int);
                parameters[0].Value = myParameter;
                comm.Parameters = parameters;
                comm.CommandType = CommandType.StoredProcedure;
                conn.Open();
                using(var rdr = comm.ExecuteReader())
                {
                    while(rdr.Read())
                    {
                        list.Add(
                            new MyItem{
                                Name = rdr["NameColumn"].ToString(),
                                UserId = rdr["ID"]
                            });
                    }
                    return list;
                }
            }
        }
    }
    

    In your databound controls, you can get at the new values in the itemtemplate with your typical

    <%#Eval("Name") %> <%#Eval("UserId") %>
    

    What I’m actually doing here is binding the controls to a list of actual objects instead of the datatable that is constructed with the datasource control. By doing that, I can do whatever I need to do with those lists before binding it to the control. In this case, I bump the two lists together and add items for those that do not exist in one list but exist in the other. Not sure if this is exactly what you needed, but this should be enough to give you some ideas.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a basic DropDownList bound to a ObjectDataSource: <asp:DropDownList ID=DropDownList1 runat=server AutoPostBack=True DataSourceID=objDataSource1
I have a dropdownlist connected to a objectdatasource. How can I get the DataValueField=TypeId
objectdatasource is not referencing the correct constructor depending on the parameters I have(scaled down
I have a formview, connected to an objectDataSource. It's a pretty easy code in
I have an DropDownList bound to an ObjectDataSource. when I select a row in
In ASP.NET, I have a FormView which is bound to an ObjectDataSource. The FormView
I have a DropDownList that populates a GridView according to the selected value. I
I have a FormView (bound to an ObjectDataSource) that contains a CheckBoxList that I'd
I have a FormView control with Two text Boxes. Data source for the Controls
I am using subsonic and a gridview with objectdatasource (I have not used an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.