2017-08-30 78 views
1

我試圖用刀尖在網格上的每一行顯示細節每當在特定的小區用戶所指向的每一行。它應該顯示每一行的細節,但它只顯示第一行的細節。誰能幫我?如何閱讀網

for (int i = 1; i <= e.Row.Cells.Count - 1; i++) 
{ 
    if (e.Row.Cells[i].Text == "0" || string.IsNullOrEmpty(e.Row.Cells[i].Text) || e.Row.Cells[i].Text == "&nbsp;") 
    { 
     e.Row.Cells[i].Text = ""; 
    } 
    else 
    { 
     e.Row.Cells[i].BackColor = System.Drawing.Color.Blue; 

     dateSetExport.Tables.Clear(); 
     dateSetExport.Reset(); 
     SqlParameter[] param = new SqlParameter[2]; 
     param[1] = new SqlParameter("@Startdate", gvDetails.HeaderRow.Cells[i].Text); 
     param[0] = new SqlParameter("@Employe_Id", e.Row.Cells[0].Text.Split('-')[0]); 
     DataTable dt1 = DataHelper.getDataTableExecuteSP("usp_GetToolTip", param); 
     dt1.TableName = "ToolTip"; 
     dateSetExport.Tables.Add(dt1); 
     string tooltip = ""; 
     for (int j = 0; j < dt1.Rows.Count; j++) 
     { 
      tooltip = tooltip + dt1.Rows[j]["normal_working_hours"].ToString() + " Hours : " + dt1.Rows[j]["description"].ToString()+"\n\n"; 
     } 
     e.Row.Cells[i].ToolTip = tooltip; 
    } 
} 
+0

哪些電網事件是你創建的工具提示? 。 –

+0

工具提示=提示+ dt1.Rows [j]的[ 「normal_working_hours」]的ToString()+ 「時間:」。+ dt1.Rows [j]的[ 「描述」]的ToString()+ 「\ n \ n」 個;與小時 – vicky

回答

0

您可以使用其他的foreach以循環的所有行:

foreach (GridViewRow row in GridView.Rows) 
{ 
    if (e.Row.RowType == DataControlRowType.DataRow) 
    { 
     //do your staff 
    } 
} 

但對我來說,你應該使用GridView_RowDataBound事件:

protected void GridView_RowDataBound(Object sender, GridViewRowEventArgs e) 
{ 
    if (e.Row.RowType == DataControlRowType.DataRow) 
    { 
     for (int i = 1; i <= e.Row.Cells.Count - 1; i++) 
     { 
     if (e.Row.Cells[i].Text == "0" || string.IsNullOrEmpty(e.Row.Cells [i].Text) || e.Row.Cells[i].Text == "&nbsp;") 
     { 
    e.Row.Cells[i].Text = ""; 
      } 
    else 
    { 
     e.Row.Cells[i].BackColor = System.Drawing.Color.Blue; 

     dateSetExport.Tables.Clear(); 
     dateSetExport.Reset(); 
     SqlParameter[] param = new SqlParameter[2]; 
     param[1] = new SqlParameter("@Startdate", gvDetails.HeaderRow.Cells[i].Text); 
     param[0] = new SqlParameter("@Employe_Id", e.Row.Cells[0].Text.Split('-')[0]); 
     DataTable dt1 = DataHelper.getDataTableExecuteSP("usp_GetToolTip", param); 
     dt1.TableName = "ToolTip"; 
     dateSetExport.Tables.Add(dt1); 
     string tooltip = ""; 
     for (int j = 0; j < dt1.Rows.Count; j++) 
     { 
     tooltip = tooltip + dt1.Rows[j]["normal_working_hours"].ToString() + " Hours : " + dt1.Rows[j]["description"].ToString()+"\n\n"; 
     }`enter code here` 
     e.Row.Cells[i].ToolTip = tooltip; 
     } 
    } 
    } 
    } 
+0

我使用RowDataBound事件 – vicky

+0

相處應將描述是否命中爲每行或只有一次的事件? –

+0

不是每個行,但對於第1排 – vicky