Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/302.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在foreach-asp.netc中从数据库调用Div_C#_Html_Asp.net_Foreach - Fatal编程技术网

C# 在foreach-asp.netc中从数据库调用Div

C# 在foreach-asp.netc中从数据库调用Div,c#,html,asp.net,foreach,C#,Html,Asp.net,Foreach,我的数据库行是这样的val1-val2-val5,在我的aspx页面中我得到了5个div,它们的id是val1,val2,val3。。。等等,所有这些都是虚假的。我希望它们与基于信息的数据库行一致 我用这个方法, string query = @"SELECT [Params] FROM [Products] WHERE Id = '"+id+"'"; string result= Library.Database.ExecuteScalar(query).ToSt

我的数据库行是这样的val1-val2-val5,在我的aspx页面中我得到了5个div,它们的id是val1,val2,val3。。。等等,所有这些都是虚假的。我希望它们与基于信息的数据库行一致

我用这个方法,

 string query = @"SELECT [Params]     
 FROM [Products] WHERE Id = '"+id+"'";
        string result= Library.Database.ExecuteScalar(query).ToString();

        string[] results;
        results= result.Split('-');

        foreach (var item in results)
        {
            switch (item)
            {
                case "val1": val1.Visible = true;
                    break;
                case "val2": val2.Visible = true;
                    break;
                case "val3": val3.Visible = true;
                    break;
                case "val4": val4.Visible = true;
                    break;
                case "val5": val5.Visible = true;
                    break;
            }
        }
例如,我想知道是否有一种方法可以在没有开关盒的情况下实现这一点

    foreach (Literal item in results)
      {item.visible = true }

谢谢..

嗯。你可以试试这样的东西

foreach(var item in results)
{
Control Div_In_the_Page = FindControl(item);
if(Div_In_the_Page  != null)
    Div_In_the_Page.visible = true;
}
这只是一个你可以尝试的模型。我不能完全肯定

 Div_In_the_Page.visible = true; //dont know if this will work. Else just use the css attributes to sort that out 
当您想从服务器端编辑div时,需要确保div具有此属性

<div runat="server"><!-- put things in here --></div>

Div_在_页面中为空。