2011-08-08 106 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" />  
相關問題