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.
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") %>'
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.
John
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)"
RugbyJohn
Member
67 Points
114 Posts
dropdown binding in detailsview
May 01, 2012 04:02 PM|LINK
Hi
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.
Any advice?
Ta
john
Bimalvv
Contributor
2356 Points
478 Posts
Re: dropdown binding in detailsview
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.
Bimal
RugbyJohn
Member
67 Points
114 Posts
Re: dropdown binding in detailsview
May 01, 2012 05:18 PM|LINK
Qin Dian Tan...
All-Star
113532 Points
12480 Posts
Microsoft
Re: dropdown binding in detailsview
May 03, 2012 08:39 AM|LINK
Hi,
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") %>'
Thanks,
If you have any feedback about my replies, please contactmsdnmg@microsoft.com.
Microsoft One Code Framework
RugbyJohn
Member
67 Points
114 Posts
Re: dropdown binding in detailsview
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.
John
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">
<ItemTemplate>
<asp:Label ID="LblSchName" runat="server" Text='<%# Bind("School_Name") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="DDSchools" runat="server"
DataSourceID="SqlSchools" DataTextField="School_Name"
SelectedValue='<%# Bind("School_id") %>'
DataValueField="School_id">
</asp:DropDownList>
</EditItemTemplate>
</asp:TemplateField>