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
see
Creating Custom Columns for the ASP.NET Datagrid
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html/creatingcustomcolumns.asp
http://www.csharphelp.com/archives/archive212.html
if(e.Item.ItemIndex>=0)
{
//绑定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
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>