2012-03-29 25 views

回答

2

我假設你正在尋找的財產是GridViewRow.RowIndex。要從DropDownLis中獲取SelectedIndexChanged事件的行參考,可以使用它的NamingContainer屬性:

private void DropDownList1_SelectedIndexChanged(object sender, System.EventArgs e) 
{ 
    DropDownList ddl = (DropDownList)sender; 
    GridViewRow row = (GridViewRow)ddl.NamingContainer; 
    int rowIndex = row.RowIndex; 
    // if you want to get the reference to the other DropDown in this row 
    DropDownList ddl2 = (DropDownList)row.FindControl("DropDownList2"); 
} 
1

您可以處理DropDownList的SelectedIndexChanged事件。

protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) 
{ 
     GridViewRow gvr = (GridViewRow)((DropDownList)sender).Parent.Parent; 
     string rowNumber= GridView1.DataKeys[gvr.RowIndex].Value.ToString(); 
} 
相關問題