2015-07-02 30 views
0

更改选定的索引我有10列和 GridView的我有号码的项目从1到10 下拉列表列表当我在GridView中单击单元格我想列的索引(不是行)和 该索引应该是dropdownlist的选择索引。当GridView的点击单元格,然后在DropDownList中

+0

在循环中使用grid.HeaderRow.Cells。它会给你列索引 –

+0

你可以写一些代码吗? – zvonnkko

回答

0
 //Get Cell Index 
     int cellindex = GridView.SelectedRow.DataItemIndex; 

     //Get HeaderText of that cell 
     string headerRowText = GridView.HeaderRow.Cells[cellindex].Text; 

     //Loopthrough, find that header text, get column # of that col. 
     foreach (DataControlField col in GridView.Columns) 
     { 
      if (col.HeaderText.ToLower().Trim() == headerRowText .ToLower().Trim()) 
      { 
       return GridView.Columns.IndexOf(col); 
      } 
     } 
+0

//获取单元格索引 int cellindex = GridView.SelectedRow.DataItemIndex;这是行索引而非单元格索引 – zvonnkko

相关问题