Try :
<asp:DropDownList ID="DropDownList1" runat="server" DataValueField="pid"
Height="20px" Width="130px"
onselectedindexchanged="DropDownList1_SelectedIndexChanged" AutoPostBack="true">
</asp:DropDownList><asp:dropdownlist id="DropDownList2" runat="server" datavaluefield="autoid" xmlns:asp="#unknown">
Height="20px" Width="130px">
</asp:DropDownList></asp:dropdownlist>
and in the .cs :
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
int pid =Convert.ToInt32(DropDownList1.SelectedValue.ToString());
Filldrop1(pid);
}
private void Filldrop1(int pid)
{
string connstr = ConfigurationManager.ConnectionStrings["connstr"].ConnectionString;
SqlConnection con = new SqlConnection(connstr);
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandType = CommandType.Text;
cmd.CommandText = "select fyyear from yearly where pid="+pid;
DataSet ds = new DataSet();
SqlDataAdapter adp = new SqlDataAdapter();
adp.Fill(ds);
con.Close();
if (ds.Tables[0].Rows.Count > 0)
{
DropDownList2.DataSource = ds.Tables[0];
DropDownList2.DataTextField = "fyyear";
DropDownList2.DataBind();
DropDownList2.Items.Insert(0, "--select--");
}
}