且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何将值从sqldatasource传递到下拉列表

更新时间:2022-05-19 02:01:43

ConnectionStrings:ConnectionString%&gt ;



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