我尝试将默认值分配给当前正在登录的用户,以便他们查看自己的个人资料。
这是数据源:
<asp:SqlDataSource ID="SqlDataProfile" runat="server" ConnectionString="<%$ ConnectionStrings:RegistrationConnectionString %>" SelectCommand="SELECT username, email, studIC, password, studGuardian, studPhone, studAddress, studClass, studName FROM RegStudents WHERE (username LIKE @username + '%')" UpdateCommand="UPDATE RegStudents SET username = @username, password = @password, studName = @studName, studClass = @studClass, studAddress = @studAddress, studPhone = @studPhone, studGuardian = @studGuardian, studIC = @studIC WHERE (username LIKE @username + '%')">
<SelectParameters>
<asp:Parameter Name="username" Type="String" DefaultValue="@username" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="username" />
<asp:Parameter Name="password" />
<asp:Parameter Name="studName" />
<asp:Parameter Name="studClass" />
<asp:Parameter Name="studAddress" />
<asp:Parameter Name="studPhone" />
<asp:Parameter Name="studGuardian" />
<asp:Parameter Name="studIC" />
</UpdateParameters>
</asp:SqlDataSource>
这是我背后的代码:
public partial class ProfilePage : System.Web.UI.Page {
protected void Page_Load(object sender, EventArgs e) {
SqlDataProfile.SelectParameters["username"].DefaultValue =User.Identity.Name;
}
当我将默认值设置为现有用户名时,它完全有效,但不能使用上面的代码。
<asp:Parameter Name="username" Type="String" DefaultValue="amanda123" />