如何在GridView中比较两列值?

时间:2010-09-10 16:44:59

标签: c# .net asp.net

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

          }

     }
 }

我想在网格视图中比较两个模板列, 但它没有工作..............请给出比较两列GridView的正确方法。谢谢

2 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分:0)

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

      }