2011-08-08 74 views
2

我在asp.net中有一个datagrid,带有一个boundfield。在RowCommand事件上,我想获取这个绑定字段的值。列标签中的boundfield如下所示:在C#中GridView中获取boundfield的值#

<asp:BoundField DataField="LoginID" HeaderText="LoginID" InsertVisible="False" 
       ReadOnly="True" SortExpression="LoginID" /> 

随附的C#会是什么?

感谢

+1

假设你的意思是GridV iew不是DataGrid? – Curt

回答

2

在Row_Command事件可以检索点击行这样的指标:

void GridView_RowCommand(Object sender, GridViewCommandEventArgs e) 
    { 

    //Check if it's the right CommandName... 
    if(e.CommandName=="Add") 
    { 
     //Get the Row Index 
     int index = Convert.ToInt32(e.CommandArgument); 

     // Retrieve the row 
     GridViewRow row = ContactsGridView.Rows[index]; 

     // Here you can access the Row Cells 
     row.Cells[1].Text 

    } 
    }  
0
protected void gv_research_RowCommand(object sender, GridViewCommandEventArgs e) 
     { 
      try 
      { 
       int index = Convert.ToInt32(e.CommandArgument); 

       if (e.CommandName == "editResearch") 
       { 

        txt_researchName.Text = gv_research.Rows[index].Cells[1].Text.TrimEnd(); 

       } 


      } 
      catch (Exception ee) 
      { 
       string message = ee.Message; 

      } 
     } 

的.aspx:

<asp:ImageButton ID="btn_Edit" runat="server" CommandArgument='<%#((GridViewRow)Container).RowIndex%>' CommandName="editResearch" />  
相关问题