Dynamicaly populate object source for dropdown in Details view

C

Chicagoboy27

I am wondering how to set an object datsource or any data source for a
dropdown list that is a details view. Here is a brief set up. I have a
details view that lists a bunch of information. when a user clicks and
edit button a few of the fields become editable or unhidden in this
example..... There are two types of roles for this system and depending
on which role you are in you have a different data source for the
dropdown list.... Here is what I have so far.

details view Info: Two routes one hidden and one not the hidding will
switch once the use clicks the edit button.

<asp:DetailsView ID="DetailsView1" Cellpadding="5" runat="server"
AutoGenerateRows="False" DataSourceID="ObjectDataSource3"
Height="50px" Width="250px" GridLines="None" ForeColor="#333333"
Font-Size="80%" >

<Fields>

<asp:TemplateField HeaderText="Route:" SortExpression="route"
HeaderStyle-Width="30%" Visible="true">
<ItemTemplate>
<asp:Label ID="lblRoute" runat="server" Text='<%#
Eval("route")%>'></asp:Label>
</ItemTemplate>
<ItemStyle Wrap="False" />
</asp:TemplateField>

<asp:TemplateField HeaderText="Route:" SortExpression="route"
HeaderStyle-Width="30%" Visible="false">
<ItemTemplate>
<asp:DropDownList ID="ddlRoute" DataSourceID="ObjectDataSource5"
DataTextField="route" DataValueField="route" Font-Size="98%"
runat="server" SelectedValue='<%# Eval("route")%>' ></asp:DropDownList>
</ItemTemplate>
<ItemStyle Wrap="False" />
</asp:TemplateField>

</Fields>
</asp:DetailsView>


Code: I have tried setting the Datasource ID like below but it does not
seem to work....


if (Session["UserIsManager"] == "true")
{
((DropDownList)DetailsView1.FindControl("ddlRoute")).DataSourceID =
ObjectDataSource1.ToString();
}

Any suggestions would be appreciated.. Thanks again.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top