Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/magento/5.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# 如何比较GridView中的两列值?_C#_.net_Asp.net - Fatal编程技术网

C# 如何比较GridView中的两列值?

C# 如何比较GridView中的两列值?,c#,.net,asp.net,C#,.net,Asp.net,我想比较网格视图中的两个模板列, 但它不起作用…………请给出比较GridView两列的正确方法。谢谢模板列呈现自己的内容。您必须获取每个控件并在模板中比较这两个控件,方法是使用FindControl并比较基础值。Cell.Text仅对绑定控件有用。我是否遗漏了什么。你想比较哪些列?@Conrad Frix:事实上,我在模板列中使用了一个DropDownList,我想根据column2值绑定它。@Brain:请给我一个简短的例子。。。因此,对我来说,这将更有效率…………谢谢您首先将绑定列转换为模板

我想比较网格视图中的两个模板列,
但它不起作用…………请给出比较GridView两列的正确方法。谢谢

模板列呈现自己的内容。您必须获取每个控件并在模板中比较这两个控件,方法是使用FindControl并比较基础值。Cell.Text仅对绑定控件有用。

我是否遗漏了什么。你想比较哪些列?@Conrad Frix:事实上,我在模板列中使用了一个DropDownList,我想根据column2值绑定它。@Brain:请给我一个简短的例子。。。因此,对我来说,这将更有效率…………谢谢您首先将绑定列转换为模板列。然后在此模板列中放置一个标签,以便可以使用FindControl。
 protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
 { 
     string[] Cardio = (string[])objDocter.getDocter_acc_prof();

     if (e.Row.RowType == DataControlRowType.DataRow)
     {
         if (e.Row.Cells[2].Text == "Heart problem")
         {
              DropDownList ddlAssignDoc 
                  = (DropDownList)e.Row.FindControl("ddlAssignDoc");
              ddlAssignDoc.DataSource = Cardio;
              ddlAssignDoc.DataBind();

          }

     }
 }
     if (((Label)e.Row.FindControl("lblProblemName")).Text == "Heart problem") 
     { 
          DropDownList ddlAssignDoc  
              = (DropDownList)e.Row.FindControl("ddlAssignDoc"); 
          ddlAssignDoc.DataSource = Cardio; 
          ddlAssignDoc.DataBind(); 

      }