you can not access DropDownList1
and DropDownList2
directly because there are TemplateField
for the DetailsView
control. After data binding you can use :
DropDownList1 myDropDownList =(DropDownList)UserProfile..Rows[0].Cells[0].FindControl("DropDownList1");
string state = myDropDownList .SelectedItem.Text;
for passing the parameter you need to use OnUpdating Event.
<asp:SqlDataSource ID="UserProfileDataSource" runat="server"
OnUpdating="UserProfileDataSource_Updating"
ConnectionString="<%$ ConnectionStrings:DefaultConnection %>"
SelectCommand="SELECT [fname], [lname], [address], [city], [state], [zip], [phoneNum], [autoCarrier], [policyNum], [accountid] ,[UserId] FROM [UserProfile] WHERE ([UserId] = @UserId)"
OnSelecting="UserProfileDataSource_Selecting"
OnUpdating="OnSqlUpdating"
UpdateCommand="UPDATE UserProfile SET
stateId = @stateId,
carrierId = @carrierId,
fname = @fname,
lname= @lname,
address = @address,
city = @city,
state = @state,
zip = @zip,
phoneNum = @phoneNum,
autoCarrier = @autoCarrier,
policyNum = @policyNum
WHERE ([UserId] = @UserId)">
<SelectParameters>
<asp:Parameter Name="UserId" Type="Object" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="fname" />
<asp:Parameter Name="lname" />
<asp:Parameter Name="address" />
<asp:Parameter Name="city" />
<asp:Parameter Name="state" />
<asp:Parameter Name="zip" />
<asp:Parameter Name="phoneNum" />
<asp:Parameter Name="autoCarrier" />
<asp:Parameter Name="policyNum" />
<asp:Parameter Name="stateId" />
<asp:Parameter Name="carrierId" />
<asp:Parameter Name="UserId" />
</UpdateParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:DefaultConnection %>" SelectCommand="SELECT [StateId], [State_en] FROM [States]"></asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:DefaultConnection %>"
SelectCommand="SELECT [CarrerID], [Name] FROM ### WHERE ([AccountID] = (SELECT [accountid] FROM ### WHERE ([UserId] = @UserId)))" OnSelecting="UserProfileDataSource_Selecting">
<SelectParameters>
<asp:Parameter Name="UserId" Type="Object" />
</SelectParameters>
</asp:SqlDataSource>
then in the code behind
protected void UserProfileDataSource_Updating(object sender, SqlDataSourceCommandEventArgs e)
{
e.Command.Parameters["@ParamaterName"].Value = // The Value you get from the drop downlist
}