2010-09-13 60 views
0

是否有替代方法來重寫頁面呈現方法以使我的gridview行可點擊。這在單網格視圖模式下工作正常,但是當嵌套時,儘管代碼遍歷並且看起來沒問題,但我沒有在嵌套網格視圖上觸發選定的索引。替代重寫Render在嵌套GridViews中添加ClientScript.GetPostBackEventReference屬性

編輯:我曾嘗試在的RowDataBound以下行,但不知道爲什麼我沒有得到所選擇的指數射擊

e.Row.Attributes["onclick"] = ClientScript.GetPostBackClientHyperlink(e.Row.Parent.Parent, "Select$" + e.Row.RowIndex); 

protected override void Render(HtmlTextWriter writer) 
{ 
    if (gdvServiceSchedule.Rows.Count > 0) 
    { 
     foreach (GridViewRow row in gdvServiceSchedule.Rows) 
     { 
      if (row.RowType == DataControlRowType.DataRow) 
      { 

        row.Attributes.Add("onclick", Page.ClientScript.GetPostBackEventReference(this.gdvServiceSchedule, "Select$" + row.DataItemIndex, true)); 
      } 
      if (row.RowState == DataControlRowState.Edit || row.RowState == (DataControlRowState.Edit | DataControlRowState.Alternate)) 
      { 
       GridView gv = (GridView)row.FindControl("gdvServiceScheduleVariants"); 
       if(gv.Rows.Count > 0) 
       { 
        foreach(GridViewRow row2 in gv.Rows) 
        { 
         if(row2.RowType ==DataControlRowType.DataRow) 

         { 
          row2.Attributes.Add("onclick", Page.ClientScript.GetPostBackEventReference(row.FindControl("gdvServiceScheduleVariants"), "Select$" + row2.DataItemIndex, true)); 
         } 
        } 
       } 

      } 
     } 
    } 
    base.Render(writer); 
} 

回答

0

使用MVC框架...但嚴重的是,你可以在行內而不是GridView中創建另一個自定義控件嗎?

+0

我看到的問題有兩種方法,其中一種可能是自定義控件,我只想知道問題的解決方案。 :) – Stuart 2010-09-13 21:27:38