2010-09-10 52 views
0
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。谢谢如何比较GridView中的两列值?

+0

我错过了什么。你想要比较哪些列? – 2010-09-10 16:57:40

+0

@Conrad Frix:实际上我在模板列中使用了DropDownList,我想根据column2值将其绑定。 – ashish 2010-09-10 17:27:27

回答

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

     } 
+0

@mangokum:非常感谢它工作正常。 ... – ashish 2010-09-10 18:13:51

+0

@mangokum:它是关于模板列,但如何比较绑定字段? – ashish 2010-09-10 18:14:58

+0

首先将绑定列转换为模板列。然后在此模板列中放置一个标签,以便您可以使用FindControl。 – mangokun 2010-09-20 03:01:57

0

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

+0

@Brain:请给我一个简单的例子...所以它会对我更有效率.............谢谢 – ashish 2010-09-10 17:07:33