Home Assigning DefaultValue in ASP.NET for SelectParameters
Reply: 0

Assigning DefaultValue in ASP.NET for SelectParameters

user1912 Published in June 22, 2018, 11:12 am

I'm trying to assign default value to the user that are currently login, for them to view their profile.

Here is the datasource:

<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 + '%')">
        <asp:Parameter Name="username" Type="String" DefaultValue="@username" />
        <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" />

Here is my code behind:

  public partial class ProfilePage : System.Web.UI.Page {

     protected void Page_Load(object sender, EventArgs e) { 
          SqlDataProfile.SelectParameters["username"].DefaultValue =User.Identity.Name; 

When I set the default value into existing username as below, it totally works but doesn't work with the code above.

<asp:Parameter Name="username" Type="String" DefaultValue="amanda123" />
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.327552 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO