如何将值从sqldatasource传递到下拉列表 [英] How to pass value to drop down list from sqldatasource

查看:96
本文介绍了如何将值从sqldatasource传递到下拉列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试根据当前使用的当前登录信息将值传递到下拉列表

我的意思是我需要显示当前登录用户的当前用户具有这些模块的模块名称。这些模块将从模块关系表中检索,其中的用户ID和日志会话中的用户ID是从users表中检索的,并且它们有关系。



我尝试过:



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: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>

推荐答案

ConnectionStrings:ConnectionString%> ;



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

< asp:参数 名称 = uid Type = string / >
< / SelectParameters >
ConnectionStrings:ConnectionString %>" SelectCommand="SELECT [MId], [MName] FROM [ModuleRelation] WHERE [UId]=@uid"> <SelectParameters> <asp:Parameter Name="uid" Type="string"/> </SelectParameters>


我不是真正的粉丝SqlDataSource,但如果你试图从你的SqlDataSource中提取值,这样你就可以使用它来填充DropDown,那么你可以尝试这样的事情:



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:

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);
    }
}


这篇关于如何将值从sqldatasource传递到下拉列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆