Monday, June 22, 2009

How to create Dropdownlist control for a SQL datasource using Sharepoint Designer

By default when you open a SQL datasource , and drag and drop the view to create a Input form for that datasource, the sharepoint point creates all fields as Text Boxes. This is not what a normal user wants.It would be greate when he can't choose a value from a dropdown and thus reduces the chances of duplicate records or wrongly spell words in the SQL tables.

Thus I have recreated the textbox control to dropdown, remember the main trick is
changing the textbox control to sharepoint inbuilt dvdropdownlist and change the binding to
'SelectedValue','SelectedIndexChanged'


<asp:SqlDataSource runat="server" id="SqlDataSource1" ConnectionString="Data Source=bwcmossdev;Initial Catalog=bwcSalesExec;User ID=sa;Password=webtech@123" ProviderName="System.Data.SqlClient" SelectCommand="SELECT rtrim(SALESMOT_SalesTeams.SalesTeamName) [SalesTeamName], SALESMOT_SalesTeams.SalesTeamManager, SALESMOT_SalesTeams.IsActive, Global_DivisionsNLocations.Description, SALESMOT_SalesTeams.SalesTeamID FROM SALESMOT_SalesTeams INNER JOIN Global_DivisionsNLocations ON SALESMOT_SalesTeams.SalesTeamDivision = Global_DivisionsNLocations.GlobalLocationId where SALESMOT_SalesTeams.isActive =1" />

<SharePoint:DVDropDownList runat="server" id="ff2{$Pos}" __designer:bind="{ddwrt:DataBind('i',concat('ff2',$Pos),'SelectedValue','SelectedIndexChanged','',ddwrt:EscapeDelims(string('')),'@SalesTeamID')}" selectedvalue="{@SalesTeamID}" datasourceid="SqlDataSource1" datatextfield="SalesTeamName" datavaluefield="SalesTeamID" />

No comments: