Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post May 03, 2012 11:07 AM by RugbyJohn
May 01, 2012 04:02 PM|LINK
I've a database of members which has a field School_no.
This links to a second database of school names which have just two fields per school School_Name and School_no.
I'm updating the members DB on a page with a detailsview and uses a dropdown list in the field update template to access the school_name. The school_no is currently showing when I load the page. How can I display School_Name? I can only do this with another
dropdown in the item template and this looks silly.
I assume I can do this with a databing/eval but cannot see how.
May 01, 2012 04:56 PM|LINK
I think you can concatenate SchoolNo - School_Name as a single field while reading from database and bind the same to the dropdownlist.
May 01, 2012 05:18 PM|LINK
May 03, 2012 08:39 AM|LINK
Just give a datasource from school with names and no. Then bind this datasource to DropDownList only, name for DataTextField and no for DataValueField. Then bind the SelectedValue property in the markup of ddl: SelectedValue='<%# Eval("School_no") %>'
May 03, 2012 11:07 AM|LINK
Sorry but I obviously didn't explain my problem properly. I already had a dropdown linked to the schools datasource in my “Edititem
template” but wanted to show the school name in the “Item template”.
I've now achieved this with the code below, The main change was linking the Schools table data in the main member data select
command and then changing the templates as shown below.
Thanks for your suggestions.
Member datasource – Select statement
SelectCommand="SELECT TabMembDetails.Member_no, TabMembDetails.Surname, TabMembDetails.School_id,
Schools.School_Name FROM TabMembDetails INNER JOIN Schools ON TabMembDetails.School_id = Schools.School_id WHERE (TabMembDetails.Member_no = @Member_no)"
Schools datasource for dropdown
<asp:SqlDataSource ID="SqlSchools" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT * FROM [Schools] ORDER BY School_Name "></asp:SqlDataSource>
Detailsview Field template for School
<asp:TemplateField HeaderText="School" SortExpression="School_Name">
<asp:Label ID="LblSchName" runat="server" Text='<%# Bind("School_Name") %>'></asp:Label>
<asp:DropDownList ID="DDSchools" runat="server"
SelectedValue='<%# Bind("School_id") %>'