you can set it the binding in the Template or do it inside DataGrid1's ItemDataBound event handler, seehttp://aspnet.4guysfromrolla.com/articles/051904-1.2.aspx
see
Creating Custom Columns for the ASP.NET Datagrid
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html/creatingcustomcolumns.asp

解决方案 »

  1.   

    这是一个很好的例子:
    http://www.csharphelp.com/archives/archive212.html
      

  2.   

    在DataGrid1_ItemDataBound的事件中绑定代码
     if(e.Item.ItemIndex>=0)
     {
       //绑定DropDownList
     }
      

  3.   

    http://www.dotnetjohn.com/articles.aspx?articleid=21
      

  4.   

    问题前面了一大步,现在已经可以调出DropDownLis里的值了,想在做到这样的效果,是否可以根据我前一个DropDownList选择的值在第二个DropDownList调用其相关值。
      

  5.   

    sure,  add OnSelectedIndexChanged and set AutoPostBack="true" on the DropDownList:<asp:DropDownList
                        Runat="server"
                        Id="DropDownList1" AutoPostBack="true"
    OnSelectedIndexChanged="ChangeDropList"/>here is an example,for EditItemTemplate, but the idea is same
    http://groups.google.com/groups?q=crms%40sina.com+dropdownlist+dependent&hl=en&lr=&ie=UTF-8&selm=ehYb6EmvCHA.2028%40TK2MSFTNGP11&rnum=1
      

  6.   

    <%@ Import Namespace="System.Data" %><script language="c#" runat="server">
      protected void Page_Load(Object sender, EventArgs e)
      {
        if (!IsPostBack)
          BindGrid();
      }  protected void BindGrid(){
        DataTable dt = new DataTable();
        DataColumn dc = new DataColumn("FirstName", typeof(string));
        dt.Columns.Add(dc);
        dc = new DataColumn("LastName", typeof(string));
        dt.Columns.Add(dc);    DataRow dr = dt.NewRow();
        dr["FirstName"] = "John";
        dr["LastName"]="Smith";
        dt.Rows.Add(dr);    dr = dt.NewRow();
        dr["FirstName"] = "Rob";
        dr["LastName"]="White";
        dt.Rows.Add(dr);    MyDataGrid.DataSource = dt.DefaultView;
        MyDataGrid.DataBind();
      }
      protected void MyDataGrid_Edit(Object sender, DataGridCommandEventArgs e)
      {
        MyDataGrid.EditItemIndex = e.Item.ItemIndex;
        BindGrid();    DropDownList dropdown =
    (DropDownList)MyDataGrid.Items[MyDataGrid.EditItemIndex].FindControl("DropDo
    wnList1");
        //bind the first list    for (int i=1; i <= 10; i++)
     dropdown.Items.Add(new ListItem(i.ToString()));    BindSecondList(dropdown);
      }  protected void MyDataGrid_Cancel(Object sender, DataGridCommandEventArgs
    e)
      {
        MyDataGrid.EditItemIndex = -1;
        BindGrid();
      }  protected void MyDataGrid_Update(Object sender, DataGridCommandEventArgs
    e)
      {
        string sMessage = "";
        DropDownList dropdown =
    (DropDownList)e.Item.FindControl("DropDownList1");
        DropDownList dropdown2 =
    (DropDownList)e.Item.FindControl("DropDownList2");    sMessage += "You selected " + dropdown.SelectedItem.Text + "<BR>";
        sMessage += " and " + dropdown2.SelectedItem.Text + "<BR>";    Message.Text = sMessage;
        MyDataGrid.EditItemIndex = -1;
        BindGrid();
      } void ChangeDropList(Object sender, EventArgs e)
     {   DropDownList dropdown = ( DropDownList)sender;
       BindSecondList(dropdown);} void BindSecondList(DropDownList parentDropDown)
     {
         string sText= parentDropDown.SelectedItem.Value;     DropDownList dropdown =
    (DropDownList)MyDataGrid.Items[MyDataGrid.EditItemIndex].FindControl("DropDo
    wnList2");//just a demo, do your database lookup here
        ArrayList a = new ArrayList();
      a.Add( sText+"1");
      a.Add( sText+"2");
      dropdown.DataSource = a;
       dropdown.DataBind();
     }</script>
    <html>
    <body>
      <form runat="server">
      <center>
        <asp:Label id="Message" EnableViewState="false" ForeColor="#CC3300"
    Font-Size="11pt" runat="server"/><p>
        <ASP:DataGrid
          id="MyDataGrid"
          runat="server"
          OnEditCommand="MyDataGrid_Edit"
          OnCancelCommand="MyDataGrid_Cancel"
          OnUpdateCommand="MyDataGrid_Update"
          AutoGenerateColumns="True">
     <Columns>
     <asp:TemplateColumn>
              <ItemTemplate>
      <asp:Button id="btnEdit" runat="server" CommandName="Edit" Text="Edit"/>
              </ItemTemplate>
              <EditItemTemplate>
      <asp:Button id="btnUpdate" runat="server" CommandName="Update"
    Text="Update" />
      <asp:Button id="btnCancel" runat="server" CommandName="Cancel"
    Text="Cancel" />
                      <asp:DropDownList
                        Runat="server"
                        Id="DropDownList1" AutoPostBack="true"
    OnSelectedIndexChanged="ChangeDropList"/>
                      <asp:DropDownList
                        Runat="server"
                        Id="DropDownList2"/>
              </EditItemTemplate>
       </asp:TemplateColumn>
     </Columns>
          </asp:DataGrid>
      </center></form>
    </body>
    </html>
      

  7.   

    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_vstechart/html/vbtchTopQuestionsAboutASPNETDataGridServerControl.asp