I have a drop down list that displays all the titles from my table in the database. This works fine, however, i want it to display the title of whichever person the query has searched for.

For example, the list has all the titles in, i have clicked on my link which shows me the details for a person, and i want the value that is shown in the drop down list to be the title of the person the query has searched for, and then listing the list of titles again after this value.

How can I do this?

<asp:DropDownList ID="ddlTitle" runat="server"  DataSourceID="obdsGetTitleForDropDown" DataTextField="Title" 
DataValueField="Title_RefNo" Width="100%">
</asp:DropDownList>

Thanks

Recommended Answers

All 3 Replies

cfcf

You can do it programmatically with linq if you know how to use that.
Thats my favorite way of making customized queries on different events.

A code example if you know visual basic.net:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Using myEnt As New PicturesEntities()
            Dim tagsN = From tag In myEnt.Tags
                        Select tag.TagName

            TagLB.DataSource = tagsN
            TagLB.DataSourceID = ""
            TagLB.DataBind()
        End Using
    End Sub

Yes you can do it by below way..

//once you have bind your drop down, define object of ListItem.
ListItem objListItem = DropDownList1.Items.FindByValue("Title_RefNo value retrieved from query for particular person ");
if (objListItem != null)
{
    DopDownList1.SelectedValue = objListItem .Value;
    objListItem .Selected = true;
}

that's all...

I have a drop down list that displays all the titles from my table in the database. This works fine, however, i want it to display the title of whichever person the query has searched for.

For example, the list has all the titles in, i have clicked on my link which shows me the details for a person, and i want the value that is shown in the drop down list to be the title of the person the query has searched for, and then listing the list of titles again after this value.

How can I do this?

<asp:DropDownList ID="ddlTitle" runat="server"  DataSourceID="obdsGetTitleForDropDown" DataTextField="Title" 
DataValueField="Title_RefNo" Width="100%">
</asp:DropDownList>

Thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.