vadim vadim - 10 months ago 73
ASP.NET (C#) Question

Sql concatenate dropdownlist

I'm having trouble pulling sql data when I concatenate my drop down list with two columns. I would like to combine the Last Name (lName) + First Name (fName) and pull the data on those names. Here is what I have so far.

<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"
DataSourceID="SqlDataSource3" DataTextField="lName" DataValueField="lName"
<asp:ListItem Value="Select">Select</asp:ListItem>

<asp:SqlDataSource ID="SqlDataSource3" runat="server"
ConnectionString="<%$ ConnectionStrings:TestDBConnectionString1 %>"
SelectCommand="SELECT (lName + fName) AS zName FROM CoaTest"></asp:SqlDataSource>

Then I have a formview with all the Databounds in it and it's sql connection looks like this:

<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:TestDBConnectionString1 %>"
DeleteCommand="DELETE FROM [CoaTest] WHERE [Id] = @Id"
SelectCommand="SELECT Id, fName, lName, agency, title, gen, hired, AppS,
course, Location, SessNum, SDate, EDate, Hours, SitUps, pushUps, rTime,
Grade FROM CoaTest WHERE (lName = @lName)"

UpdateCommand="UPDATE [CoaTest] SET [fName] = @fName, [lName] = @lName, [agency] = @agency, [title] = @title, [gen] = @gen, [hired] = @hired, [AppS] = @Apps, [course] = @course, [Location] = @Location, [SDate] = @SDate, [EDate] = @EDate, [Hours] = @Hours WHERE [Id] = @Id">
<asp:Parameter Name="Id" Type="Int32" />
<asp:ControlParameter ControlID="DropDownList1" Name="lName"
PropertyName="SelectedValue" Type="String" />

<asp:Parameter Name="fName" Type="String" />
<asp:Parameter Name="lName" Type="String" />
<asp:Parameter Name="Agency" Type="String" />
<asp:Parameter Name="title" />
<asp:Parameter Name="gen" />
<asp:Parameter Name="hired" />
<asp:Parameter Name="Apps" />
<asp:Parameter Name="course" />
<asp:Parameter Name="Location" />
<asp:Parameter Name="SDate" />
<asp:Parameter Name="EDate" />
<asp:Parameter Name="Hours" />
<asp:Parameter Name="Id" Type="Int32" />

This works if I just have it pull by Last Name (lName) but when I try to concatenate it doesn't pull the data from the formview. Thank you in advance!!

Answer Source

Change select command for dropdown to SELECT Id, (lName + fName) AS zName FROM CoaTest, change dropdown's DataValueField value to Id and selecting data to FormView by Id instead of by name