Click here to Skip to main content
15,886,067 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to pass value to drop down list based on the current used who current logged in
I mean I need to show the module name where the current who logged in now user has these module. these module will be retrieved from module relation table where user id in it and in the logging session the user id is retrieved from users table and they have relation.

What I have tried:

ASP.NET
<asp:SqlDataSource ID="SqlDataSource8" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"

SelectCommand="SELECT [MId], [MName] FROM [ModuleRelation] WHERE [UId]=@uid">
<SelectParameters>

<asp:Parameter Name="uid" Type="string"/>
</SelectParameters>
Posted
Updated 21-Jul-16 3:59am
v2

1 solution

I'm not really a fan of SqlDataSource, but if you are trying to extract the value from your SqlDataSource so you can use it to populate your DropDown then you could try something like this:

C#
protected void Page_Load(object sender, EventArgs e)
{

    DataView dvSql = (DataView)SqlDataSource8.Select(DataSourceSelectArguments.Empty);
    foreach (DataRowView drvSql in dvSql)
    {
        string moduleName = drvSql["MName"].ToString();
        DropDownList1.Items.Clear();
        DropDownList1.Items.Add(moduleName);
    }
}
 
Share this answer
 
Comments
Member 12618369 21-Jul-16 10:28am    
Thanks for this but I could not find DataView in the c# library is it DataSourceView?
Richard Deeming 21-Jul-16 10:33am    
Make sure you've got a using System.Data; line at the top of your code file.
Vincent Maverick Durano 21-Jul-16 10:35am    
Thanks for that, Richard.
Member 12618369 21-Jul-16 10:47am    
Thanks Richard
I got error with SqlDataSource8 red under line says that afield initializer cannot reference the non static field, method or property
Richard Deeming 21-Jul-16 10:52am    
So you're not using the code that Vincent posted?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900