DropDownList模板列中的按钮可以触发SelectedIndexChanged事件

在前台加上事件DropDownList_SelectedIndexChanged
<asp:TemplateColumn HeaderText="">
      <ItemTemplate>
       <asp:DropDownList ID="dep2" Runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList_SelectedIndexChanged"></asp:DropDownList>
      </ItemTemplate>
      <EditItemTemplate>
       <asp:DropDownList ID="dep" Runat="server"></asp:DropDownList>
      </EditItemTemplate>
</asp:TemplateColumn>

在后台添加事件
protected void DropDownList_SelectedIndexChanged(object sender, System.EventArgs e)
  {
   Response.Write(((DropDownList)sender).SelectedItem);
  }
事件不能是private的,这里的sender就是这个下拉框,类型转换一下就能使用了

DropDownList ddl = (DropDownList)sender;
TableCell cell = (TableCell)ddl.Parent;
DataGridItem item = (DataGridItem)cell.Parent;
Response.Write(item.Cells[0].Text);

posted on 2005-11-26 02:09  扎悉的乐  阅读(400)  评论(0)    收藏  举报

导航