2011-08-08 2 views
2

私はバインドフィールドを持つasp.netでデータグリッドを持っています。 RowCommandイベントでは、この境界フィールドの値を取得します。列タグのバインドフィールドは、次のようになります。C#のgridviewでboundfieldの値を取得する

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

付随するC#は何ですか?

おかげRow_Commandイベントで

+1

GridVを意味すると仮定DataGridは表示されませんか? – Curt

答えて

2

あなたは、このようにクリックされた行のインデックスを取得できます。

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" />  
関連する問題