2011-08-03 1 views
0

템플릿 필드 중 하나에 radiobuttonlist와 dropdownlist가있는 Gridview가 있습니다. SelectedIndexChanged 이벤트에서 radiobuttonlist가있는 행에 어떻게 액세스 할 수 있습니까? 그래서 gridview의 해당 템플릿 필드 안에있는 모든 드롭 다운 목록을 업데이트하지 않습니다. 나는 현재 코드를 가지고 있지 않지만 어떤 도움이 크게 될Gridview template radiobuttonlist SelectedInxedChanged, 해고 당했을 때의리스트 얻기

답변

1
<asp:TemplateField HeaderText="Column with ListControls" > 
    <ItemTemplate> 
     <asp:DropDownList ID="DropdownList1" OnSelectedIndexChanged="SomethingChanged" AutoPostBack="true" runat="server" > 
      <asp:ListItem Text="1"></asp:ListItem> 
      <asp:ListItem Text="2"></asp:ListItem> 
     </asp:DropDownList> 
     <asp:RadioButtonList ID="RadioButtonList1" OnSelectedIndexChanged="SomethingChanged" AutoPostBack="true" runat="server"> 
      <asp:ListItem Text="1"></asp:ListItem> 
      <asp:ListItem Text="2"></asp:ListItem> 
     </asp:RadioButtonList> 
    </ItemTemplate> 
</asp:TemplateField> 

코드 숨김 VB.NET 감사합니다 :

Protected Sub SomethingChanged(ByVal sender As Object, ByVal e As EventArgs) 
    'in this example this handler is used for both, Dropdownlist and RadiobuttonList' 
    Dim listControl = DirectCast(sender, ListControl) 
    Dim row = DirectCast(listControl.NamingContainer, GridViewRow) 
    Dim item = listControl.SelectedItem 
    'with FindControl on the row you could also find controls in other columns...' 
End Sub 

C 번호 :

protected void SomethingChanged(object sender, EventArgs e) 
{ 
    //in this example this handler is used for both, Dropdownlist and RadiobuttonList 
    var listControl = (ListControl)sender; 
    var row = (GridViewRow)listControl.NamingContainer; 
    var item = listControl.SelectedItem; 
    //with FindControl on the row you could also find controls in other columns... 
} 
+0

굉장이 그것을 이잖아합니다. 도움을 주셔서 감사합니다. –