只有Button系列的控件才有commandName属性。

解决方案 »

  1.   

    那你把ItemCommand事件里要做的处理,放到ListControl.SelectedIndexChanged 事件里不也一样吗?
      

  2.   

    <%@ Import Namespace="System.Data" %>
    <%@ Import Namespace="System.Data.SqlClient" %>
    <Script language="C#" runat="server">
    void Page_Load(Object o, EventArgs e)
    {
    if (!IsPostBack)
    {
    SqlDataAdapter da = new SqlDataAdapter("select * from authors",
    "Server=localhost;Database=pubs;UID=sa;PWD=;");
    DataTable dt= new DataTable();
    da.Fill(dt); DataGrid1.DataSource = dt.DefaultView;
    DataGrid1.DataBind(); for (int i=0; i < dt.Rows.Count; i++)
    DropDownList0.Items.Add(i.ToString());
    }
    }

    void ChildSelectionChanged(Object o, EventArgs e)
    {
      DropDownList ddl = (DropDownList)o;
      Response.Write(ddl.SelectedItem.Text);
    }void ChangeSelection(Object o, EventArgs e)
    {
      DropDownList parent = (DropDownList)o;
      int n = parent.SelectedIndex;
      DropDownList ddl = (DropDownList)DataGrid1.Items[n].FindControl("DropDownList1");

      Random rd  = new Random();
      for (int i=0; i < 10; i++)
      {
       ddl.Items.Add(rd.Next(100).ToString());
      }
    }</script><form runat="server">
    <asp:DropDownList id="DropDownList0" runat="Server" AutoPostback="true" OnSelectedIndexChanged="ChangeSelection"/>
    <asp:datagrid id="DataGrid1" GridLines="Both" runat="server">
    <Columns>
    <ASP:TemplateColumn HeaderText="编号">
    <ItemTemplate>
    <asp:DropDownList id="DropDownList1" runat="Server" AutoPostback="true" OnSelectedIndexChanged="ChildSelectionChanged"/>
    </ItemTemplate>
    </ASP:TemplateColumn>
    </Columns>
    </asp:datagrid>   <asp:Button id=btn runat=server Text="Submit" />
    </form>
      

  3.   

    用以下代码试试。    
    Private Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
           dropdownlist1.Attributes.Add("onlclick", "DataGrid1_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs)")
       Sub End