2017-08-30 7 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; 
    } 
} 
あなたはすべての行ループするために、別のforeachを使用することができます
+0

グリッドイベントを? ToString()+ "時間:" + dt1.Rows [j] ["description"] ToString()+ "\ n \ n"; –

+0

ツールチップ=ツールチップ+ dt1.Rows [j] ["normal_working_hours"時間とともにdesciptionを取得する – vicky

答えて

0

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

すべての行または1回だけイベントにヒットしますか? –

+0

すべての行ではなく1行目 – vicky

関連する問題