2012-03-25 33 views
1

我有一個gridiview,它給了我一個列表中20個成員的輸出。現在,我要支付的工資只有特定的人,只有這些人,其複選框被選中我嘗試了一些東西像這樣的如下:如何訪問GridView中的多行

protected void Button_Click(object sender, EventArgs e) 
    { 
     foreach (GridViewRow GVR in GridView.Rows) 
     { 
      if (GVR.RowType == DataControlRowType.DataRow) 
      { 
        CheckBox c = (CheckBox)GVR.FindControl("MemberCheck"); 
        if (c.Checked) 
        { 

         string DividendAmount = GridView.Rows[0].Cells[5].Text; 
         string MOP = GridView.Rows[0].Cells[4].Text; 
        } 
      } 
     } 
    } 

但問題是,這段代碼我只能訪問任何一個特定的行,但如果我選擇了n行呢?

+0

如果問題不明確,請讓我知道 – 2012-03-25 19:01:26

+1

您是不是每次訪問每行一個foreach循環?你是否想要訪問表中除了設置爲變量GVR的行之外的其他行? – 2012-03-25 19:06:40

回答

1

你的意思是?

string DividendAmount = GVR.Cells[5].Text; 
string MOP = GVR.Cells[4].Text;