2010-09-10 99 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