Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/296.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/29.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# 状态[“DataTypeIndex”]=value;} } 私人运营商 { 得到 { var@operator=ViewState[“operator”]; if(@operator!=null) 返回(操作员)@操作员; 返回运算符。无; } 设置{Vi_C#_Asp.net_Dynamic_Viewstate_Web Controls - Fatal编程技术网

C# 状态[“DataTypeIndex”]=value;} } 私人运营商 { 得到 { var@operator=ViewState[“operator”]; if(@operator!=null) 返回(操作员)@操作员; 返回运算符。无; } 设置{Vi

C# 状态[“DataTypeIndex”]=value;} } 私人运营商 { 得到 { var@operator=ViewState[“operator”]; if(@operator!=null) 返回(操作员)@操作员; 返回运算符。无; } 设置{Vi,c#,asp.net,dynamic,viewstate,web-controls,C#,Asp.net,Dynamic,Viewstate,Web Controls,状态[“DataTypeIndex”]=value;} } 私人运营商 { 得到 { var@operator=ViewState[“operator”]; if(@operator!=null) 返回(操作员)@操作员; 返回运算符。无; } 设置{ViewState[“Operator”]=value;} } 私有void BindDropDownLists() { 列\u列表\u用于\u filter.ConnectionString=connection; string item=“--

状态[“DataTypeIndex”]=value;} } 私人运营商 { 得到 { var@operator=ViewState[“operator”]; if(@operator!=null) 返回(操作员)@操作员; 返回运算符。无; } 设置{ViewState[“Operator”]=value;} } 私有void BindDropDownLists() { 列\u列表\u用于\u filter.ConnectionString=connection; string item=“--选择--”; column_list_for_filter.SelectCommand=“SELECT DATA_TYPE+''+convert(varchar(10),ROW_NUMBER()(按数据_TYPE排序))作为数据_TYPE,column_NAME来自信息_SCHEMA.COLUMNS,其中(表_NAME='RESULT'和列_NAME IN('Column1','Column2','Column3','Column4')); DropDownList5.DataTextField=“COLUMN\u NAME”; DropDownList5.DataValueField=“数据类型”; DropDownList5.DataBind(); DropDownList5.Items.Insert(0,item); } 受保护的void DropDownList5\u SelectedIndexChanged(对象发送方,事件参数e) { DataTypeIndex=DropDownList5.SelectedIndex; if(DropDownList5.SelectedValue.Contains(“十进制”)) { DataType=DataType.Decimal; } CreateDataTypeControl(); //else if(DropDownList5.SelectedValue.Contains(“varchar”)) //{ //DataType=DataType.Varchar; //} //else if(DropDownList5.SelectedValue.Contains(“datetime”)) //{ //DataType=DataType.DateTime; //} //else if(DropDownList5.SelectedValue.Contains(“int”)) //{ //DataType=DataType.Integer; //} } 受保护的无效范围\u DDL\u Decimal\u SelectedIndexChanged(对象发送方,事件参数e) { var ddl=(DropDownList)发送方; 开关(ddl.SelectedIndex) { 案例1: Operator=WebApplication1.Operator.Equal; 打破 } CreateRangeControls(); } 受保护的void createdynamiccontrols\u decimal() { int i=DataTypeIndex.getValuerDefault(); ++一,; TableRow行=新TableRow(); row.ID=“TableRow”; TableCell cell1=新的TableCell(); cell1.ID=“TableCell_2;”; DropDownList Range_DDL_Decimal=新的DropDownList(); Range_DDL_Decimal.ID=“RandeDDL_Decimal”+i.ToString(); 范围_DDL _Decimal.Items.Insert(0,新列表项(“--Select--”,“--Select--”); 插入(1,新列表项(“相等”、“相等”)); 插入(2,新列表项(“NotEqual”,“NotEqual”)); 插入(3,新列表项(“大于”、“大于”)); 插入(4,新列表项(“小于”、“小于”)); 插入(5,新列表项(“大于或等于”、“大于或等于”)); 插入(6,新列表项(“小于或等于”、“小于或等于”)); 插入(7,新列表项(“包含”,“包含”)); 插入(8,新列表项(“为空”、“为空”); 范围_DDL_Decimal.Items.Insert(9,新列表项(“不为空”、“不为空”); 插入(10,新列表项(“介于”、“介于”)之间); Range\u DDL\u Decimal.SelectedIndexChanged+=新系统.EventHandler(Range\u DDL\u Decimal\u SelectedIndexChanged); Range_DDL_Decimal.AutoPostBack=true; cell1.Controls.Add(范围_DDL _小数); ////将TableCell添加到TableRow row.Cells.Add(cell1); 动态过滤表。行。添加(行); dynamic_filter_table.EnableViewState=true; ViewState[“动态过滤器表”]=真; } 受保护的void CreateRangeTextBoxes() { int j=DataTypeIndex.getValuerDefault(); ++j; TableCell cell2=新的TableCell(); cell2.ID=“范围”; TextBox tb1=新的TextBox(); TextBox tb2=新的TextBox(); 标签lbl1=新标签(); 标签lbl2=新标签(); //为添加的每个文本框设置唯一的ID tb1.ID=“lowerbound_u2;”+j.ToString(); tb2.ID=“上限”+j.ToString(); lbl1.Text=“LowerBound:”; lbl1.Font.Size=FontUnit.Point(10); lbl1.Font.Bold=true; lbl1.Font.Name=“Arial”; lbl2.Text=“上限:”; lbl2.Font.Size=FontUnit.Point(10); lbl2.Font.Bold=true; lbl2.Font.Name=“Arial”; cell2.Controls.Add(lbl1); 细胞2。对照。添加(tb1); cell2.Controls.Add(lbl2); 细胞2.对照组.添加(tb2); TableRow rowtwo=动态过滤器表格。FindControl(“TableRow”)作为TableRow; 第二行。单元格。添加(单元格2); 动态过滤器表.Rows.Add(第二行); dynamic_filter_table.EnableViewState=true; ViewState[“动态过滤器表”]=真; } 受保护的无效按钮1\u单击(对象发送者,事件参数e) { int j=DropDownList5.SelectedIndex; ++j; 面板6.可见=真实; JQGrid9.Visible=true; 发现控件不工作 TextBox lowerbound=dynamic_filter_table.FindControl(“lowerbound_”+j.ToString())作为TextBox; TextBox upperbound=dynamic_filter_table.FindControl(“upperbound_”+j.ToString())作为TextBox; DropDownList range=dynamic_filter_table.FindControl(“RandeDDL_Decimal”+j.ToString())作为DropDownList; con.Open();
SqlDataAdapter da=新SqlDataAdapter(“从结果中选择*,其中“+DropDownList5.Text+DDL2.Text+”>=“+LowerBound.Text+”和“+DropDownList5.Text+“您可以保留/保存您首先创建的步骤/选定值,然后需要在Page Init上重新创建这些步骤/选定值。@Aristos您能帮我在上面添加几行代码吗?一种方法是,这里还有其他方法,等等。”
  private void BindDropDownLists()
     {
         column_list_for_filter.ConnectionString = connection;
         string item = "--Select--";

         column_list_for_filter.SelectCommand = "SELECT DATA_TYPE + '_' + convert(varchar(10), ROW_NUMBER() OVER(ORDER BY DATA_TYPE))as DATA_TYPE, COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE (TABLE_NAME = 'RESULT' AND COLUMN_NAME IN ('Column1','Column2','Column3','Column4'))";
         DropDownList5.DataTextField = "COLUMN_NAME";
         DropDownList5.DataValueField = "DATA_TYPE";
         DropDownList5.DataBind();
         DropDownList5.Items.Insert(0, item);
     }

  protected void createdynamiccontrols_decimal()
     {
         int i = DropDownList5.SelectedIndex;
         ++i;
         TableRow row = new TableRow();
         row.ID = "TableRow_";
         TableCell cell1 = new TableCell();
         cell1.ID = "TableCell_";

         DropDownList Range_DDL_Decimal = new DropDownList();
         Range_DDL_Decimal.ID = "RandeDDL_Decimal" + i.ToString();
         Range_DDL_Decimal.Items.Insert(0, new ListItem("--Select--", "--Select--"));
         Range_DDL_Decimal.Items.Insert(1, new ListItem("Equal", "Equal"));
         Range_DDL_Decimal.Items.Insert(2, new ListItem("NotEqual", "NotEqual"));
         Range_DDL_Decimal.Items.Insert(3, new ListItem("greater than", "greater than"));
         Range_DDL_Decimal.Items.Insert(4, new ListItem("lesser than", "lesser than"));
         Range_DDL_Decimal.Items.Insert(5, new ListItem("greater than or equal to", "greater than or equal to"));
         Range_DDL_Decimal.Items.Insert(6, new ListItem("lesser than or equal to", "lesser than or equal to"));
         Range_DDL_Decimal.Items.Insert(7, new ListItem("Contains", "Contains"));
         Range_DDL_Decimal.Items.Insert(8, new ListItem("Is Null", "Is Null"));
         Range_DDL_Decimal.Items.Insert(9, new ListItem("Is Not Null", "Is Not Null"));
         Range_DDL_Decimal.Items.Insert(10, new ListItem("Between", "Between"));
         Range_DDL_Decimal.AutoPostBack = true;
         Range_DDL_Decimal.SelectedIndexChanged += new System.EventHandler(Range_DDL_Decimal_SelectedIndexChanged);
         cell1.Controls.Add(Range_DDL_Decimal);

         //// Add the TableCell to the TableRow  
         row.Cells.Add(cell1);
         dynamic_filter_table.Rows.Add(row);
         dynamic_filter_table.EnableViewState = true;
         ViewState["dynamic_filter_table"] = true;
     }

     protected void Range_DDL_Decimal_SelectedIndexChanged(object sender, EventArgs e)
     {
         int j = DropDownList5.SelectedIndex;
         ++j;

         TableCell cell2 = new TableCell();

         TextBox tb1 = new TextBox();
         TextBox tb2 = new TextBox();

         Label lbl1 = new Label();
         Label lbl2 = new Label();

         // Set a unique ID for each TextBox added      
         tb1.ID = "lowerbound_" + j.ToString();
         tb2.ID = "upperbound_" + j.ToString();
         lbl1.Text = "LowerBound:";
         lbl1.Font.Size = FontUnit.Point(10);
         lbl1.Font.Bold = true;
         lbl1.Font.Name = "Arial";

         lbl2.Text = "UpperBound:";
         lbl2.Font.Size = FontUnit.Point(10);

         lbl2.Font.Bold = true;
         lbl2.Font.Name = "Arial";

         cell2.Controls.Add(lbl1);
         cell2.Controls.Add(tb1);
         cell2.Controls.Add(lbl2);
         cell2.Controls.Add(tb2);

         TableRow rowtwo = dynamic_filter_table.FindControl("TableRow_") as TableRow;
         rowtwo.Cells.Add(cell2);


         dynamic_filter_table.Rows.Add(rowtwo);

         dynamic_filter_table.EnableViewState = true;
         ViewState["dynamic_filter_table"] = true;

     }

protected override object SaveViewState()
 {
      /***1. Retain DDL 1 selected text
       2. Retain DDL 2 selected text DDL2 generated by DDL 1
       3. Retain Tb1.text and tb2.text generated by DDL2 ***/
       //How to Proceed  
 }

protected override void LoadViewState(object savedState)
 {
       //How to Proceed
 }

   protected void Button1_Click(object sender, EventArgs e)
    {

         int j = DropDownList5.SelectedIndex;
         ++j;
         Panel6.Visible = true;
         JQGrid9.Visible = true;

         //Find Control not working
         TextBox lowerboundd = dynamic_filter_table.FindControl("lowerbound_" + j.ToString()) as TextBox;

         TextBox upperbound = dynamic_filter_table.FindControl("upperbound_" + j.ToString()) as TextBox;

          con.Open();

         // **How to pass values to this query from savedstate**  
         SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM RESULT WHERE " + DropDownList5.Text + DDL2.Text + " >= " + lowerboundd.Text + " AND " + DropDownList5.Text + " <= " + upperbound.Text, con);
         DataSet ds = new DataSet();
         da.Fill(ds);
         con.Close();
         Session["DataforSearch"] = ds.Tables[0];

     }

 protected void Page_Load(object sender, EventArgs e)
    {

        Panel6.Visible = false;
        JQGrid9.Visible = false;


        if (Session["DataforSearch"] != null)
        {
            Panel6.Visible = true;
            JQGrid9.Visible = true;
            JQGrid9.DataSource = Session["DataforSearch"] as string;

         }

       if (!IsPostBack)
        {
            BindDropDownLists();
        }

        else
        {
            if (!String.IsNullOrEmpty(DropDownList5.SelectedValue))
            {
                if (DropDownList5.SelectedValue.Contains("decimal"))
                {
                    createdynamiccontrols_decimal();
                }

                else if (DropDownList5.SelectedValue.Contains("varchar"))
                {
                    createdynamiccontrols_varchar();
                }
                else if (DropDownList5.SelectedValue.Contains("datetime"))
                {
                    createdynamiccontrols_datetime();
                }

                else if (DropDownList5.SelectedValue.Contains("int"))
                {
                    createdynamiccontrols_int();
                }

            }

        }
    }

  protected void Page_PreInit(object sender, EventArgs e)
     {

         if (!IsPostBack)
         {
             BindDropDownLists();
         }

         else
         {
             if (!String.IsNullOrEmpty(DropDownList5.SelectedValue))
             {
                 if (DropDownList5.SelectedValue.Contains("decimal"))
                 {
                     createdynamiccontrols_decimal();
                 }

                 else if (DropDownList5.SelectedValue.Contains("varchar"))
                 {
                     createdynamiccontrols_varchar();
                 }
                 else if (DropDownList5.SelectedValue.Contains("datetime"))
                 {
                     createdynamiccontrols_datetime();
                 }

                 else if (DropDownList5.SelectedValue.Contains("int"))
                 {
                     createdynamiccontrols_int();
                 }

             }

         }
internal enum DataType
{
    None = 0,
    Decimal
}

internal enum Operator
{
    Equal,
    GreaterThan,
    None
}

public partial class _Default : Page
{
    private DataType DataType
    {
        get
        {
            object dataType = ViewState["DataType"];
            if (dataType != null) return (DataType)dataType;
            return DataType.None;
        }
        set { ViewState["DataType"] = value; }
    }
    private int? DataTypeIndex
    {
        get { return ViewState["DataTypeIndex"] as int?; }
        set { ViewState["DataTypeIndex"] = value; }
    }
    private Operator Operator
    {
        get
        {
            var @operator = ViewState["Operator"];
            if (@operator != null)
                return (Operator)@operator;
            return Operator.None;
        }
        set { ViewState["Operator"] = value; }
    }
    private void BindDropDownLists()
    {
        column_list_for_filter.ConnectionString = connection;
        string item = "--Select--";

        column_list_for_filter.SelectCommand = "SELECT DATA_TYPE + '_' + convert(varchar(10), ROW_NUMBER() OVER(ORDER BY DATA_TYPE))as DATA_TYPE, COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE (TABLE_NAME = 'RESULT' AND COLUMN_NAME IN ('Column1','Column2','Column3','Column4'))";
        DropDownList5.DataTextField = "COLUMN_NAME";
        DropDownList5.DataValueField = "DATA_TYPE";
        DropDownList5.DataBind();
        DropDownList5.Items.Insert(0, item);
    }

    protected void DropDownList5_SelectedIndexChanged(object sender, EventArgs e)
    {
        DataTypeIndex = DropDownList5.SelectedIndex;
        if (DropDownList5.SelectedValue.Contains("decimal"))
        {
            DataType = DataType.Decimal;
        }
        CreateDataTypeControl();
        //else if (DropDownList5.SelectedValue.Contains("varchar"))
        //{
        //DataType = DataType.Varchar;
        //}
        //else if (DropDownList5.SelectedValue.Contains("datetime"))
        //{
        //DataType = DataType.DateTime;
        //}
        //else if (DropDownList5.SelectedValue.Contains("int"))
        //{
        //DataType = DataType.Integer;
        //}
    }
    protected void Range_DDL_Decimal_SelectedIndexChanged(object sender, EventArgs e)
    {
        var ddl = (DropDownList)sender;
        switch (ddl.SelectedIndex)
        {
            case 1:
                Operator = WebApplication1.Operator.Equal;
                break;
        }
        CreateRangeControls();
    }

    protected void createdynamiccontrols_decimal()
    {
        int i = DataTypeIndex.GetValueOrDefault();
        ++i;
        TableRow row = new TableRow();
        row.ID = "TableRow_";
        TableCell cell1 = new TableCell();
        cell1.ID = "TableCell_";

        DropDownList Range_DDL_Decimal = new DropDownList();
        Range_DDL_Decimal.ID = "RandeDDL_Decimal" + i.ToString();
        Range_DDL_Decimal.Items.Insert(0, new ListItem("--Select--", "--Select--"));
        Range_DDL_Decimal.Items.Insert(1, new ListItem("Equal", "Equal"));
        Range_DDL_Decimal.Items.Insert(2, new ListItem("NotEqual", "NotEqual"));
        Range_DDL_Decimal.Items.Insert(3, new ListItem("greater than", "greater than"));
        Range_DDL_Decimal.Items.Insert(4, new ListItem("lesser than", "lesser than"));
        Range_DDL_Decimal.Items.Insert(5, new ListItem("greater than or equal to", "greater than or equal to"));
        Range_DDL_Decimal.Items.Insert(6, new ListItem("lesser than or equal to", "lesser than or equal to"));
        Range_DDL_Decimal.Items.Insert(7, new ListItem("Contains", "Contains"));
        Range_DDL_Decimal.Items.Insert(8, new ListItem("Is Null", "Is Null"));
        Range_DDL_Decimal.Items.Insert(9, new ListItem("Is Not Null", "Is Not Null"));
        Range_DDL_Decimal.Items.Insert(10, new ListItem("Between", "Between"));
        Range_DDL_Decimal.SelectedIndexChanged += new System.EventHandler(Range_DDL_Decimal_SelectedIndexChanged);
        Range_DDL_Decimal.AutoPostBack = true;
        cell1.Controls.Add(Range_DDL_Decimal);

        //// Add the TableCell to the TableRow  
        row.Cells.Add(cell1);
        dynamic_filter_table.Rows.Add(row);
        dynamic_filter_table.EnableViewState = true;
        ViewState["dynamic_filter_table"] = true;
    }
    protected void CreateRangeTextBoxes()
    {
        int j = DataTypeIndex.GetValueOrDefault();
        ++j;

        TableCell cell2 = new TableCell();
        cell2.ID = "Range";

        TextBox tb1 = new TextBox();
        TextBox tb2 = new TextBox();

        Label lbl1 = new Label();
        Label lbl2 = new Label();

        // Set a unique ID for each TextBox added      
        tb1.ID = "lowerbound_" + j.ToString();
        tb2.ID = "upperbound_" + j.ToString();
        lbl1.Text = "LowerBound:";
        lbl1.Font.Size = FontUnit.Point(10);
        lbl1.Font.Bold = true;
        lbl1.Font.Name = "Arial";

        lbl2.Text = "UpperBound:";
        lbl2.Font.Size = FontUnit.Point(10);

        lbl2.Font.Bold = true;
        lbl2.Font.Name = "Arial";

        cell2.Controls.Add(lbl1);
        cell2.Controls.Add(tb1);
        cell2.Controls.Add(lbl2);
        cell2.Controls.Add(tb2);

        TableRow rowtwo = dynamic_filter_table.FindControl("TableRow_") as TableRow;
        rowtwo.Cells.Add(cell2);


        dynamic_filter_table.Rows.Add(rowtwo);

        dynamic_filter_table.EnableViewState = true;
        ViewState["dynamic_filter_table"] = true;
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        int j = DropDownList5.SelectedIndex;
        ++j;
        Panel6.Visible = true;
        JQGrid9.Visible = true;

        Find Control not working
        TextBox lowerboundd = dynamic_filter_table.FindControl("lowerbound_" + j.ToString()) as TextBox;
        TextBox upperbound = dynamic_filter_table.FindControl("upperbound_" + j.ToString()) as TextBox;
        DropDownList range = dynamic_filter_table.FindControl("RandeDDL_Decimal" + j.ToString()) as DropDownList;

        con.Open();

        SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM RESULT WHERE " + DropDownList5.Text + DDL2.Text + " >= " + lowerboundd.Text + " AND " + DropDownList5.Text + " <= " + upperbound.Text, con);
        DataSet ds = new DataSet();
        da.Fill(ds);
        con.Close();
        Session["DataforSearch"] = ds.Tables[0];

    }
    protected void Page_Load(object sender, EventArgs e)
    {
        Panel6.Visible = false;
        JQGrid9.Visible = false;

        if (Session["DataforSearch"] != null)
        {
            Panel6.Visible = true;
            JQGrid9.Visible = true;
            JQGrid9.DataSource = Session["DataforSearch"] as string;

        }
        CreateDataTypeControl();
        CreateRangeControls();
    }

    void CreateDataTypeControl()
    {
        switch (DataType)
        {
            case DataType.Decimal:
                createdynamiccontrols_decimal();
                break;
        }
    }

    void CreateRangeControls()
    {
        switch (Operator)
        {
            case WebApplication1.Operator.GreaterThan:
            case Operator.Equal:
                CreateRangeTextBoxes();
                break;
        }
    }
}