How to get the cell value by column name not by index in GridView in asp.net

后端 未结 10 1593
轻奢々
轻奢々 2020-12-01 06:21

I am having a gridview in asp.net and now I want the cell value by the column name but not by the cell index.

How would be it possible

10条回答
  •  失恋的感觉
    2020-12-01 06:31

    protected void CheckedRecords(object sender, EventArgs e)
    
        {
           string email = string.Empty;
            foreach (GridViewRow gridrows in GridView1.Rows)
    
            {
    
                CheckBox chkbox = (CheckBox)gridrows.FindControl("ChkRecords");
        if (chkbox != null & chkbox.Checked)
    
                {
    
        int columnIndex = 0;
                    foreach (DataControlFieldCell cell in gridrows.Cells)
                    {
                        if (cell.ContainingField is BoundField)
                            if (((BoundField)cell.ContainingField).DataField.Equals("UserEmail"))
                                break;
                        columnIndex++; 
                    }
    
    
                    email += gridrows.Cells[columnIndex].Text + ',';
                      }
    
            }
    
            Label1.Text = "email:" + email;
    
        }                           
    

提交回复
热议问题